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

VulpesRank #55 · 29.2K reputationPosted Mar 23, 2012, 2:36 AM EDT
Anyway, here's some example C++/CLI code:
Karthik AgarwalRank #2,270 · 620 reputationPosted Mar 23, 2012, 2:50 AM EDT
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 ^'
VulpesRank #55 · 29.2K reputationPosted Mar 23, 2012, 3:20 AM EDT
Karthik AgarwalRank #2,270 · 620 reputationPosted Mar 23, 2012, 4:25 AM EDT
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?
VulpesRank #55 · 29.2K reputationPosted Mar 23, 2012, 5:29 AM EDT
Karthik AgarwalRank #2,270 · 620 reputationPosted Mar 23, 2012, 5:40 AM EDT
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.
VulpesRank #55 · 29.2K reputationPosted Mar 23, 2012, 6:31 AM EDT
You'd have to perform the same exercise on all other properties whose Browsable attribute you wish to change.
Karthik AgarwalRank #2,270 · 620 reputationPosted Mar 23, 2012, 9:33 PM EDT
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:
VulpesRank #55 · 29.2K reputationPosted Mar 24, 2012, 3:58 AM EDT
Karthik AgarwalRank #2,270 · 620 reputationPosted Mar 28, 2012, 11:32 PM EDT
{
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
VulpesRank #55 · 29.2K reputationPosted Mar 29, 2012, 5:35 AM EDT
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();