C # Combobox set value,
Because ComboxItem is an Object, and the control does not have the Value attribute, You need to customize a class and use its Object to store Text and Value.
Public class ComboxItem
{
Private string text;
Private string values;
Public string Text
{
Get {return this. text ;}
Set {this. text = value ;}
}
Public string Values
{
Get {return this. values ;}
Set {this. values = value ;}
}
Public ComboxItem (string _ Text, string _ Values)
{
Text = _ Text;
Values = _ Values;
}
Public override string ToString ()
{
Return Text;
}
}
Assignment Example 1:
CbDictData. Items. Add (new ComboxItem ("User Type", "D1 "));
CbDictData. Items. Add (new ComboxItem ("region Dictionary", "D2 "));
CbDictData. Items. Add (new ComboxItem ("region Dictionary", "D3 "));
Assignment Example 2:
ComboxItem [] values = {
New ComboxItem ("User Type", "D1 "),
New ComboxItem ("region Dictionary", "D2 "),
New ComboxItem ("region Dictionary", "D3 ")
};
CbDictData. Items. AddRange (values );
Value example:
String strDict = (ComboxItem) cbDictData. SelectedItem). Values;