如何为 DataGridViewComboBox 列设置值? [英] How to set value to DataGridViewComboBox Column?
问题描述
我想知道如何设置 DataGridViewComboBox 单元格的值.我已经将 DataGridViewComboBox 与 DataSource 绑定.但我想为此数据源设置新值.
I want to know how to set the value of a DataGridViewComboBox cell. I already bind the DataGridViewComboBox with DataSource. But I want to set new value to this this datasource.
这是我目前所拥有的:
gvList.Rows[0].Cells[0].value = "Select";
但它抛出一个错误说:格式异常:DataGridViewComboBox 单元格值无效.
But it throws an error saying: Format Exception: DataGridViewComboBox Cell value is not valid .
我怎样才能做到这一点而不会出错?
How could I achieve this without error?
推荐答案
该错误是由于您已将 DataSource
绑定到 ComboBox
列并且同时您分配 Select 它也试图在 DataSource
其绑定中找到相同的位置.您最好的选择是将相同的内容添加到您绑定到 ComboBox
列
The error is due to the fact that you have bound a DataSource
to the ComboBox
column and while you assign Select its trying to locate the same in the DataSource
its bound too.
Your best bet will be to add the same to the original DataSource which you bind to the ComboBox
column
这篇关于如何为 DataGridViewComboBox 列设置值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!