Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have one datagridview with combo-box and check box.

Image for better explanation

when i try to get values from datagridview in data table it works fine. But when i tried to get value from database in same scheme of datagridview it adds rows in datagridview but does not sets combo box or check box value. For setting datasource i tried.
C#
DataTable dt = db.getSecurityCheck(dateTimePickerDate.Value);
dataGridView1.DataSource = null;
dataGridView1.DataSource = dt;`

Do i need to manually set the values by running for each loop on retrieved datatable and setting value for each cell individually.
Posted
Updated 15-Jun-16 22:58pm
v3
Comments
George Jonsson 5-Sep-14 6:43am    
How do you set the DataSource for the ComboBox?
You have to consider DisplayMember and ValueMember for the ComboBox.
Chetan Saini 5-Sep-14 6:50am    
DataGridViewComboBoxColumn dcombo;
dcombo.DataSource=db.getBuses();
dcombo.DisplayMember = "BusId";
dcombo.ValueMember = "Id";

I guess...

Instead of below...
C#
DataGridViewComboBoxColumn dcombo; 
dcombo.DataSource=db.getBuses();
dcombo.DisplayMember = "BusId";
dcombo.ValueMember = "Id";

You should have...
C#
DataGridViewComboBoxColumn dcombo;
dcombo = dataGridView1.Columns["ComboBoxColumnName"];
dcombo.DataSource = db.getBuses();
dcombo.DisplayMember = "BusId";
dcombo.ValueMember = "Id";
 
Share this answer
 
Comments
Chetan Saini 5-Sep-14 21:32pm    
Tradit dash i think dcombo is the name of column only.
That is an object. You have to assign something to that as I did. So first you need to get the column and then do anything to it.
 
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