为什么在初始加载DataGridViewComboBoxColumn显示空值 [英] Why on Initial load DataGridViewComboBoxColumn showing empty value
本文介绍了为什么在初始加载DataGridViewComboBoxColumn显示空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
DataGridViewComboBoxColumn clnStatus = new DataGridViewComboBoxColumn();
clnStatus.DataPropertyName =状态;
clnStatus.AutoComplete = true;
clnStatus.ValueMember =absent;
clnStatus.Name =缺席 - 离开 - 存在;
clnStatus.DataSource = new string [] {absent,present,leave};
dataGridView1.Columns.Insert(0,clnStatus);
但是这会导致我的datagridview的空值如下。我应该怎么做才能获得一个值?
解决方案
Value属性对窗体加载没有影响。而不是使用静态ComboBox项目,尝试将组合与您的数据源绑定,并设置以下属性:
comboBoxColumn.DataPropertyName = Column_Name;
然后使用每个单元格上的.Value来确保每一行都有预期的值。 >
Hi all I have binded my datagridview with DataGridViewComboBoxColumn as follows
DataGridViewComboBoxColumn clnStatus = new DataGridViewComboBoxColumn();
clnStatus.DataPropertyName = "Status";
clnStatus.AutoComplete = true;
clnStatus.ValueMember = "absent";
clnStatus.Name = "Absent - Leave - Present";
clnStatus.DataSource = new string[] { "absent", "present", "leave" };
dataGridView1.Columns.Insert(0, clnStatus);
But this is resulting in an empty value for my datagridview as follows. What should I do inorder to get the one value selected
解决方案
The Value property has no effects on form load. Instead of use static ComboBox items, try to bind the combo with your datatable source and set the following property:
comboBoxColumn.DataPropertyName = "Column_Name";
Then use the .Value on each cell to be sure every row has the expected value.
这篇关于为什么在初始加载DataGridViewComboBoxColumn显示空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文