How to show Enum type members in a DataGridViewComboBox?

后端 未结 4 917
醉酒成梦
醉酒成梦 2021-02-03 10:30

What else I have to do in order to show ReadAccess enum members in this DatagridViewComboBox?

ReadDataGridViewComboBoxColumn.Items.Clear();
ReadDa         


        
4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-03 11:12

    You should not convert enum value to the int. Use this code if you have an error like "invalid value":

    ReadDataGridViewComboBoxColumn.DataSource = new ReadAccess[]
    { ReadAccess.None, ReadAccess.Allowed }
    .Select(value => new { Display=value.ToString(), Value=value })
    .ToList();
    

提交回复
热议问题