如何在 vb.net 中的 DataGridView 中填充组合框列?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2399410/
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-09 14:45:36  来源:igfitidea点击:

How to fill combobox column in DataGridView in vb.net?

vb.netdatagridview

提问by meenakshi

My DataGridView contains three columns, column types are checkbox, textbox and combobox.

我的 DataGridView 包含三列,列类型是复选框、文本框和组合框。

How can I load a row's combobox when the checkbox in the same row is checked?

How can I load a row's combobox when the checkbox in the same row is checked?

回答by jjj

maybe this could help (example)

也许这可以帮助(示例)

Dim dgvcc As DataGridViewComboBoxCell
dgvcc = DataGridView1.Rows(2).Cells(0)
dgvcc.Items.Add("comboitem1")
dgvcc.Items.Add("comboitem2")

source

来源

回答by Jai Gehlawat

You can bind like this -

你可以这样绑定 -

 Dim dtRange As DataTable = GetQueryTable("select range_name from table_name")
    Me.grid_column_name.ValueMember = "range_name"
    Me.grid_column_name.DisplayMember = "range_name"
    Me.grid_column_name.DataSource = dtRange

and this will bind table record to complete DataGridViewColumn of DataGridView.

这将绑定表记录以完成 DataGridView 的 DataGridViewColumn。

回答by MarkInEugene

Another approach is to filter the Datasource (in my case a dataset) when you edit another column that needs to filter the combobox column. I find this super easy to code and efficient.

另一种方法是在编辑需要过滤组合框列的另一列时过滤数据源(在我的情况下是数据集)。我发现这非常容易编码且高效。

Private Sub DGV_CellBeginEdit(sender As Object, e As DataGridViewCellCancelEventArgs) Handles DGV.CellBeginEdit
Select Case e.Column.Name
    Case "TabID"
        Me.FormTabBindingSource.RemoveFilter()
        Me.FormTabBindingSource.Filter = String.Format("FormID =  {0}", DGV.Rows(e.RowIndex).Cells("FormID").Value)
    End Select
End Sub