is displaymember needed?
i got an enum
public enum colorStatus
{
green= 1,
blue= 2,
orange= 3,
}
When i bind it to the datagridviewcombobox, it works perfect.
((DataGridViewComboBoxColumn)dgSale.Columns["color"]).DataSource
= Enum.GetValues(typ开发者_JS百科eof(colorStatus));
Questions:
1) What isDisplayMember and ValueMember
that i should set for that datagridviewcombobox? When you don't specify DisplayMember
/ValueMember
, the control uses ToString
method to format the object, which gives a reasonable behavior for enum
.
If you were displaying a more complex object, you could use DisplayMember
to specify how should the object be displayed in the combobox (ToString
doesn't always return useful information).
For example, if you had class with Name
and ID
, you could set DisplayMember
to Name
- the combo box would then display names of your objects. If you also set ValueMember
to ID
then you could use SelectedValue
of the combobox to get the ID
of the currently selected object.
精彩评论