如何从DataGridViewComboBoxCell中选择一个项目 [英] How to select an item from the DataGridViewComboBoxCell

查看:84
本文介绍了如何从DataGridViewComboBoxCell中选择一个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

我将组合框绑定到了datagridview.此组合框从枚举中获取其值,如下所示:

Dear all,

I bounded combobox to the datagridview. This combobox takes its values from enum, like this:

DataGridViewComboBoxColumn comboColumn = new DataGridViewComboBoxColumn();
comboColumn.DataSource = Enum.GetNames(typeof(Duration));
comboColumn.Name = "Duration";
comboColumn.DisplayStyle = DataGridViewComboBoxDisplayStyle.ComboBox;
dataGrid.Columns.Add(comboColumn);



现在,我需要为datagridview中的每个组合框选择一个默认项,但是不必对所有组合框都使用相同的项.我该怎么办?


在此先谢谢您.



Now I need to select a default item for each of the combobox in the datagridview, but it''s not necessary to be the same item to all the combobox. How could I do that?


Thanks in advance.

推荐答案

您可以使用组合框列的DefaultCellStyle.NullValue和DefaultCellStyle.DataSourceNullValue属性.代码示例为:

You can use the DefaultCellStyle.NullValue and DefaultCellStyle.DataSourceNullValue properties of the combo box column. Code sample is:

comboColumn.DefaultCellStyle.NullValue = "dataToStore";
comboColumn .DefaultCellStyle.DataSourceNullValue = "dataToStore";


这篇关于如何从DataGridViewComboBoxCell中选择一个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆