3

I have DataGridView with 2 columns:

Fname | Age

I need to show Age in ComboBox (that i can pick the age between 1 to 100).
When I press the button (save button for example) the Age value will be saved to the database. (I work with access)

Can i get any sample in C# for this?

Alex Aza
  • 76,499
  • 26
  • 155
  • 134
Gali
  • 14,511
  • 28
  • 80
  • 105

3 Answers3

2

Did you check MSDN? It has a good example at DataGridViewComboBoxColumn Class.

Alex Aza
  • 76,499
  • 26
  • 155
  • 134
1

Have you tried using a DataGridViewComboBoxColumn?

This "represents a column of DataGridViewComboBoxCell objects", each of which display a ComboBox control in the DataGridView.

The above-linked MSDN documentation also has an example of how you might implement this. But it's even easier to do from the Visual Studio designer; you don't even have to write a single line of code.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
  • can you help me to design and populate a column(Index 1) in a datagridview(winforms) which is a comboboxcolumn? – Sukanya May 03 '12 at 10:07
-2
string value = combodisease.SelectedItem.ToString();
string str = "select test, normal, high, cost from testname join testcost on testcost.testid=testname.testid where test='"+value+"'";
SqlDataAdapter da = new SqlDataAdapter(str, cn);
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
zajonc
  • 1,935
  • 5
  • 20
  • 25