【问题标题】:How to display first element of DataGridViewComboBoxCell inside dynamic Gridview in c#?如何在 c# 的动态 Gridview 中显示 DataGridViewComboBoxCell 的第一个元素?
【发布时间】:2013-07-03 10:26:10
【问题描述】:

如何显示在动态DatGridView中创建的组合框单元格的第一个元素,就像我们可以设置的普通组合框一样

ComboBox1.SelectedIndex = 0;

但是这种情况不适用于 DataGridViewComboBoxCell,我创建了组合框单元格,如下面的代码所示,并且我正在向内部循环添加值..

DataGridViewComboBoxCell global_inhibits = new DataGridViewComboBoxCell();
for (int j = 0; j < Class_INHV.global_inhibts.Count; j++)
    global_inhibits.Items.Add(Class_INHV.global_inhibts[j]);

谁能告诉我如何显示默认添加的第一个元素?

【问题讨论】:

    标签: c# winforms


    【解决方案1】:

    试试:

     global_inhibits.Value = global_inhibits.Items[0];
    

    【讨论】:

    • 很高兴它对您有用。快乐的编码和上帝保佑你学习更多。
    【解决方案2】:

    只需设置值。您可以像

    一样明确设置它
    DataGridViewComboBoxCell global_inhibits = new DataGridViewComboBoxCell();
    global_inhibits.Value = "SomeValue";
    

    或者使用Items 使用索引

    DataGridViewComboBoxCell global_inhibits = new DataGridViewComboBoxCell();
    global_inhibits.Value = global_inhibits.Items[0];
    

    我希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-18
      相关资源
      最近更新 更多