How to set the value of a datagridviewcomboboxcell

Hi there

How can we set, programmatically, the value or the selected index of a datagridviewcomboboxcell in windows form?

I have tried it in few ways, one shown below, but without luck,


1
2
3
4
5
6
7
8
 //Populate geometry
for(int i = 0;i<NOLYRS;i++)
{	
line = readLines[i];
words = line->Split(delimiter, StringSplitOptions::RemoveEmptyEntries);
for (int word = 0; word<words->Length; word++)			
this->dataGridView1->Rows[i]->Cells[word]->Value = words[word];
 } 




Thanks

Last edited on
You need to cast the cell to a DataGridViewComboBoxCell, then you can set the value.
Try this:
1
2
3
4
    array<Object^> ^values = gcnew array<Object^> {"Item 1", "Item 2", "Item 3"};

    DataGridViewComboBoxCell^ cell = dynamic_cast<DataGridViewComboBoxCell^>(dataGridView1->Rows[0]->Cells[2]);
    cell->DataSource = values;

You need to click on the arrow to see the value.
Thank you so much!
Topic archived. No new replies allowed.