property Color DrawColor
{
Color get()
{
return draw_color;
}
void set( Color val )
{
draw_color = val;
}
}
and also the below code and what's the difference between the above and below code?
[Description ("Alignment to be used for this text"), Category ("Text Configuration")]
[TypeConverter(AlignModeList::typeid)]
property String ^ Alignment
{
String ^ get()
{
return alignment;
}
void set( String ^ val )
{
alignment = val;
}
}
public ref class AlignModeList : System::ComponentModel::StringConverter
{
public:
static array
virtual System::ComponentModel::TypeConverter::StandardValuesCollection ^ GetStandardValues(System::ComponentModel::ITypeDescriptorContext ^ context) override
{
return gcnew StandardValuesCollection(alignmode);
}
virtual bool GetStandardValuesSupported(System::ComponentModel::ITypeDescriptorContext ^ context) override
{
return true;
}
virtual bool GetStandardValuesExclusive(System::ComponentModel::ITypeDescriptorContext ^ context) override
{
return true;
}
};

VulpesRank #55 · 29.2K reputationPosted Oct 27, 2011, 6:04 AM EDT
http://msdn.microsoft.com/en-us/library/aa302326.aspx?ppud=4
VulpesRank #55 · 29.2K reputationPosted Oct 27, 2011, 2:32 AM EDT
Here you have a reference type called AlignModeList which inherits from StringConverter which itself inherits from the TypeConverter base class.
TypeConverter has virtual methods called GetStandardValues, GetStandardValuesSupported and GetStandardValuesExclusive which are being overridden here in the derived class.
The AlignModeList class also has a static string array field called alignmode which has 3 elements: "Left", "Centre" and "Right".
The GetStandardValues method creates and returns a new StandardValuesCollection object from these three elements.
The other two methods return a bool (always true) to indicate that all these values are supported exclusively within the dropdown list
The AlignModeList TypeConverter is then applied (using an attribute which identifies it by its typeid property) to a string property called Alignment.
This property has a backing field called 'alignment' (not shown in the snippet) to store the current setting: "Left", "Centre" or "Right" which is get or set in the usual fashion.
The property also has Description and Category attributes for displaying its description and the category to which it is to be allocated within the Properties Box.
DrawColor is another property to be used at design time whose backing field is called draw_color and which has Description and Category attributes. However, this is of the standard Color type and so doesn't need a custom type descriptor to display its possible values - the ColorDialog will be displayed instead.
Karthik AgarwalRank #2,270 · 620 reputationPosted Oct 27, 2011, 2:41 AM EDT
property String ^ StringSelect
{
String ^ get()
{
return sample_string;
}
void set( String ^ val )
{
sample_string = val;
}
}
VulpesRank #55 · 29.2K reputationPosted Oct 27, 2011, 3:04 AM EDT
If you can let me have a list of the possible values, I'll see if I can write the code for you when I next get time.
Karthik AgarwalRank #2,270 · 620 reputationPosted Oct 27, 2011, 3:12 AM EDT
[Description ("Sample text to be displayed in viewer"), Category ("Text Configuration")]
[TypeConverter(SidTextList::typeid)]
property String ^ TestString
{
String ^ get()
{
return sample_text;
}
void set( String ^ val )
{
array
space_delimiter[0] = ' ';
array
splitted_sid = val->Split(space_delimiter);
String ^ concat_text;
int len = splitted_sid->Length;
for each(KeyValuePair
{
if(SidLanguageData->copy_of_clicked_language == "View " + kvp.Key)
{
concat_text = "";
for(int j = 0;j < len;j++)
{
if(splitted_sid[j] != "")
{
for(int x = 0;x < SidLanguageData->language_string_id->Length;x++)
{
if(splitted_sid[j] == SidLanguageData->language_string_id[x])
{
List
if(len > 1)
{
concat_text = concat_text + values[x]->ToString();
sample_text = concat_text;
}
else
{
sample_text = values[x]->ToString();
}
}
}
}
if(splitted_sid[j]->StartsWith("X") &&
splitted_sid[j]->EndsWith("X"))
{
if(len > 1)
{
concat_text = concat_text + splitted_sid[j]->Replace("X",
SidLanguageData->max_dec_string);
sample_text = concat_text;
}
else
{
sample_text = val->Replace("X", SidLanguageData->max_dec_string);
}
}
else if(splitted_sid[j]->StartsWith("Y") &&
splitted_sid[j]->EndsWith("Y"))
{
if(len > 1)
{
concat_text = concat_text + splitted_sid[j]->Replace("Y",
SidLanguageData->max_string);
sample_text = concat_text;
}
else
{
sample_text = val->Replace("Y", SidLanguageData->max_string);
}
}
else if(splitted_sid[j]->StartsWith("'") &&
splitted_sid[j]->EndsWith("'"))
{
if(len > 1)
{
concat_text = concat_text + splitted_sid[j]->Replace("'", "");
sample_text = concat_text;
}
else
{
sample_text = val->Replace("'", "");
}
}
}
}
}
sample_text = val;
}
}
public ref class SidTextList : System::ComponentModel::StringConverter
{
public:
virtual System::ComponentModel::TypeConverter::StandardValuesCollection ^ GetStandardValues(System::ComponentModel::ITypeDescriptorContext ^ context) override
{
return gcnew StandardValuesCollection(Globals::sid_text_listbox->Items);
}
virtual bool GetStandardValuesSupported(System::ComponentModel::ITypeDescriptorContext ^ context) override
{
return true;
}
virtual bool GetStandardValuesExclusive(System::ComponentModel::ITypeDescriptorContext ^ context) override
{
return true; // return false //EDITED it should be false to make it work like combobox
}
};
VulpesRank #55 · 29.2K reputationPosted Oct 27, 2011, 5:18 AM EDT
If you mean that the user can type in a selection as well as selecting it from the dropdown (i.e. like a combobox rather than a listbox), then I didn't know that was even possible within a standard PropertyGrid.
Do you have some sample code that you're working from to do this?
Karthik AgarwalRank #2,270 · 620 reputationPosted Oct 27, 2011, 5:27 AM EDT
And if it comes to sample code the one which i posted first "DrawColor" is an editable dropdown. i want to resemble the same but with the code which i posted above.
[Description ("Foreground color"), Category ("Text Configuration")]
property Color DrawColor
{
Color get()
{
return draw_color;
}
void set( Color val )
{
draw_color = val;
}
}
For any clarifications please feel free to post back.
Karthik AgarwalRank #2,270 · 620 reputationPosted Oct 27, 2011, 6:22 AM EDT
VulpesRank #55 · 29.2K reputationPosted Oct 27, 2011, 6:30 AM EDT
Karthik AgarwalRank #2,270 · 620 reputationPosted Oct 27, 2011, 6:35 AM EDT
Suthish NairRank #92 · 22.8K reputationPosted Oct 27, 2011, 10:16 AM EDT
VulpesRank #55 · 29.2K reputationPosted Oct 28, 2011, 1:13 AM EDT
Karthik AgarwalRank #2,270 · 620 reputationPosted Oct 28, 2011, 1:50 AM EDT
VulpesRank #55 · 29.2K reputationPosted Oct 28, 2011, 2:24 AM EDT
Sam HobbsRank #107 · 20.5K reputationPosted Oct 28, 2011, 9:40 AM EDT
Suthish NairRank #92 · 22.8K reputationPosted Oct 28, 2011, 11:21 AM EDT
Sam HobbsRank #107 · 20.5K reputationPosted Oct 28, 2011, 11:27 AM EDT