Click here to Skip to main content
14,301,230 members
Rate this:
Please Sign up or sign in to vote.
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
ds = new DataSet();
da = new SqlDataAdapter("select * from holiday", con);
da.Fill(ds, "holiday");
DataTable tab = ds.Tables[0];
int i = 0;

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

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

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[^]

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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100