开发者

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

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

How can I lo开发者_如何学Pythonad a row's combobox when the checkbox in the same row is checked?


maybe this could help (example)

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

source


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.


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜