Click here to Skip to main content
15,793,452 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to i bind Data Base table values on data grid view with Combo box Column values. 

1 solution

First, set AutoGenerateColumns to false. Bind your columns explicitely:

private void BindTableData() {
dgv.Columns(0).DataPropertyName = "table_id"
dgv.Columns(1).DataPropertyName = "table_data1"
//. other columns
// before you bind combobox, you need to get the data for it.
DataTable you_table_source = GetYourComboData();
DataGridViewComboBoxColumn cb = TrYCast(dgv.Columns(your_index), DataGridViewComboBoxColumn)

cb.DataPropertyName = "your_datasource_column_name" // this is important, if you don't set this, grid datasource will not know how to set your combo
If (cb != null)
cb.DisplayMember = "your_display_column_name"
cb.ValueMember = "your_value_column_name"
cb.DataSource = your_table_source // you may have to call your_table_source.Copy instead of just setting the table - check if each row has its own instance of the datasource or it is set to the same reference (you will know if changing one row changes all others). In that case add .Copy as above

// AAAND You're done
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900