Hi i have Browsable attributes based on which i need to load the properties at run time.
In order to make it more clear i have a dropdown list where i will select any one option amongst 1,2,3. If 1 is selected i should load the properties based on that accordingly for 2 and 3. The problem here is i have some specific properties for each option i.e 1,2 and 3. The options 1 or 2 or 3 will change dynamically how to change dynamically which property should be loaded dynamically.
Hence what i am trying to do is setting Browsable property to false at design time and change the property to true based on the selected option.
Is there anything better i can do? And also how to set the Browsable property to true at run time?
Loading
VulpesPosted Mar 23, 2012, 6:36 AM
Anyway, here's some example C++/CLI code:
VulpesPosted Mar 29, 2012, 9:35 AM
http://msdn.microsoft.com/en-us/library/system.windows.forms.propertygrid.aspx
it says:
"To use the property grid, you create a new instance of the PropertyGrid class on a parent control and set SelectedObject to the object to display the properties for.
As you're still using the same object that was originally assigned (albeit with the Browsable attribute of one of its properties changed), I'd try initially:
MainForm::app_main_form->propertyGrid1->Refresh();
If that doesn't work, I'd try:
MainForm::app_main_form->propertyGrid1->SelectedObject = null; // remove object
MainForm::app_main_form->propertyGrid1->SelectedObject = MainForm::screen_setting; // re-assign
MainForm::app_main_form->propertyGrid1->Refresh();
Karthik AgarwalPosted Mar 29, 2012, 3:32 AM
{
Type ^ t = screen_setting->GetType();
PropertyInfo ^ pi = t->GetProperty("BGColor");
Type ^ bt = BrowsableAttribute::typeid;
array
safe_cast
// get private browsable field using reflection and set it to true
BindingFlags bf = BindingFlags::Instance | BindingFlags::NonPublic;
FieldInfo^ fi = bt->GetField("Browsable", bf);
fi->SetValue(attrs[0], false);
/*AttributeCollection^ attributes = TypeDescriptor::GetProperties(srcimg)[ "BGColor" ]->Attributes;
attributes[ BrowsableAttribute::typeid ] = BrowsableAttribute::Yes; */
}
MainForm::app_main_form->propertyGrid1->SelectedObject = MainForm::screen_setting;
Hi Vulpes, this is what xtactly i am doing, in run time based upon some conditon i want to make this property to "false"
[Browsable(true)]
property Color BGColor
{
Color get()
{
return bg_color;
}
void set( Color val )
{
bg_color = val;
}
}
But i am getting following Exception
An unhandled exception of type 'System.NullReferenceException' occurred in viewer.exe
Additional information: Object reference not set to an instance of an object.
so could u plz tell me to which object i am not setting the reference?
Also tell me how to refresh this Browsable attribute
VulpesPosted Mar 24, 2012, 7:58 AM
Karthik AgarwalPosted Mar 24, 2012, 1:33 AM
So is there any modification which i require to do for this case.
And I have tried as below but nothing turned up
And the property declaration is as follows:
VulpesPosted Mar 23, 2012, 10:31 AM
You'd have to perform the same exercise on all other properties whose Browsable attribute you wish to change.
Karthik AgarwalPosted Mar 23, 2012, 9:40 AM
No Vulpes you mistook my words i was asking about one property to make it clear for you but there are many in number just like that.
If this is the case what should be done.
VulpesPosted Mar 23, 2012, 9:29 AM
Karthik AgarwalPosted Mar 23, 2012, 8:25 AM
But Can you explain in detail what that code means?
I have tried this out but i am not clear about the implementation.
What i did is i have a property PresentationHandler which i have set to false and if i write as below it should be visible in the property pane right?
VulpesPosted Mar 23, 2012, 7:20 AM
Karthik AgarwalPosted Mar 23, 2012, 6:50 AM
Compilation errors in this line
Type ^ bt = BrowsableAttribute::TypeId;
The errors are as follows:
error C2597: illegal reference to non-static member 'System::Attribute::TypeId'
error C2843: 'System::Attribute::TypeId' : cannot take the address of a non-static data member or method of a managed type
error C3142: 'System::Attribute::TypeId' : you cannot take the address of a property
error C2440: 'initializing' : cannot convert from '' to 'System::Type ^'