How can I have a selected item in a combobox display the entire row in a data gridview using vb.net.

Recommended Answers

All 2 Replies

You can assign the dataset/datatable as the DataGridView's DataSource and filter the results so that it shows only the selected record from the combobox.

Dim m_dtData as New DataTable
m_dtData = FillDataTableCode
DataGridView1.DataSource = m_dtData

Private Sub Combobox1_SelectedIndexChanged()

    m_dtData.DefaultView.Filter = "ColumnName = 'Value'"

End Sub

Also if you want to try a neat little control, similar the properties window in VB when you click on any of the form controls. Drag a PropertyGrid Control from the toolbox onto your form. In your code assign your table record/row to the PropertyGrid control and take a look at the results.

Dim rowMyData as DataRow = Nothing

myDataRow = m_dtData.FindByPrimaryKeyColumnName(ComboBox1.SelectedValue)

If myDataRow IsNot Nothing Then
    PropertyGrid.SelectedObject = rowMyData
End If
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.