3

I have a DataGridView and I change one column to a DataGridViewComboBoxColumn. And I can edit the Items to put some data in it and it works.

But I want to put the Items in program, therefore, I try to use dataGridView1.Columns["drop_column"]. But it doesn't have a Items

I found this article but it's to create a new column but I already have a column Add items to DataGridViewComboBoxColumn in DataGridView during runtime.

Update: thanks to Ginosaji and Dona, I add a cast and it works now.

((DataGridViewComboBoxColumn)dataGridView1.Columns["drop_column"]).Items.Add("1");
((DataGridViewComboBoxColumn)dataGridView1.Columns["drop_column"]).Items.Add("2");
((DataGridViewComboBoxColumn)dataGridView1.Columns["drop_column"]).Items.Add("3");
Community
  • 1
  • 1
Dennys
  • 587
  • 2
  • 13
  • 33

1 Answers1

2

Here is an example:

DataGridViewComboBoxCell CBCell = new DataGridViewComboBoxCell();

CBCell = DataGridView1.Rows(0).Cells("Your column name");
CBCell.Items.Add("Your item here");
Vlad Schnakovszki
  • 8,434
  • 6
  • 80
  • 114
Doan Cuong
  • 2,594
  • 4
  • 22
  • 39
  • `-1` His `Tag` is `C#` you may want to convert that answer to `C#` also not a good comment in regards to `You can convert to C# easily using google` – MethodMan Apr 02 '13 at 15:57
  • It only took me 5 seconds to google this link http://www.developerfusion.com/tools/convert/vb-to-csharp/, and a few time to convert. I gave him an example that possible use in his case without too much efford. But anyway, i edited my answer – Doan Cuong Apr 02 '13 at 16:04
  • that's the key point as well the `OP` needs to use `google` but if you're going to post an answer it would behoove you to perhaps post it in the `language that the OP is writing in..` LOL – MethodMan Apr 02 '13 at 16:06