vb.net 将 datagridview 列类型更改为组合框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18457873/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 14:48:29  来源:igfitidea点击:

vb.net change datagridview column type to combobox

vb.netdatagridviewcomboboxtextboxcell

提问by Hilal Al-Rajhi

can I change textbox column in datagridview in vb.net to combobox column type at run time? I know that can be done in design time but I want to do that programatically.

我可以在运行时将 vb.net 中 datagridview 中的文本框列更改为组合框列类型吗?我知道这可以在设计时完成,但我想以编程方式完成。

采纳答案by AAzami

If you are in runtime you will have to remove the column and then add a combobox column. Make sure that the Items list of your combobox contains the data value or an exception will be thrown.

如果您在运行时,则必须删除该列,然后添加一个组合框列。确保组合框的项目列表包含数据值,否则将引发异常。

With DataGridView1
    If .Rows.Count = 0 Then Exit Sub
    i = Datagridview1.currentrow.index

    Dim gridComboBox As New DataGridViewComboBoxCell
    gridComboBox.Items.Add("A") 'Populate the Combobox
    gridComboBox.Items.Add("B") 'Populate the Combobox
    gridComboBox.Items.Add("C") 'Populate the Combobox
    .Item(8, i) = gridComboBox
End With