开发者

is displaymember needed?

开发者 https://www.devze.com 2023-02-17 20:59 出处:网络
i got an enum public enum colorStatus { green= 1, blue= 2, orange= 3, } When i bind it to the datagridviewcombobox, it works perfect.

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 is DisplayMember 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消