Click here to Skip to main content
15,894,740 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI friends, could you explain that how to bind data to DataGridViewComboboxColumn.I tried coding for that but it gives an error message.Here is the coding which i tried
C#
ds = new DataSet();
da = new SqlDataAdapter("select * from holiday", con);
da.Fill(ds, "holiday");
DataTable tab = ds.Tables[0];
MessageBox.Show(ds.Tables[0].Rows.Count.ToString());
int i = 0;

foreach (DataRow row in tab.Rows)
{
    dataGridView1.Rows.Add();
    
    //MessageBox.Show(row[0].ToString());
    dataGridView1[0, 1].Value=row[0].ToString();
    dataGridView1[1, i].Value = row[1].ToString();
    dataGridView1[2,i].Value = row[2].ToString();
    i++;
}
Posted
Updated 14-Mar-12 21:35pm
v3
Comments
ProEnggSoft 15-Mar-12 3:35am    
Edit: code tag added and indentation arranged - PES

1 solution

I think it will be easy to use typed DataSets for this purpose.
You can take a look at this article
General purpose class to fill DataTable(s) from DataBase and to save DataTable(s) to DataBase using reflection[^]
for easily filling the DataTables from database and saving DataTables to database.

Then to bind the DataGridViewComboboxColumn
set the DataSource property to your DataTable and
ValueMember, DisplayMember properties to field required in the table.

An example is given here
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcomboboxcolumn.aspx[^]
 
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