Csharp/C#教程:以编程方式在DataGridView中设置ComboBox的选定索引分享


以编程方式在DataGridView中设置ComboBox的选定索引

我想在避免数据绑定的同时,在DataGridView的ComboBox中设置所选索引。 它没有连接到DB。

我找到的所有解决方案都将DataGridView连接到数据库,我没有,所以我无法解决问题。

由于DataGridViewComboBoxColumn没有SelectedIndex或SelectedValue属性,您可以尝试设置值,如下例所示:

DataGridViewComboBoxColumn cmbCurrencies = (DataGridViewComboBoxColumn)myDataGridView.Columns["ComboboxCurrencyColumn"]; var currencies = entities.currencies.Select(c => c.currencyName).DefaultIfEmpty().ToList(); cmbCurrencies.DataSource = currencies; 

然后:

 for (int i = 0; i <= myDataGridView.RowCount - 1; i++) { myDataGridView.Rows[i].Cells["Index of Combobox Column"].Value = "Pound"; } 

另请参阅这是否有帮助。

上述就是C#学习教程:以编程方式在DataGridView中设置ComboBox的选定索引分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注---计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/953761.html

(0)
上一篇 2021年11月19日
下一篇 2021年11月19日

精彩推荐