Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Events for ComboBox thats inside a dataGridView
 

Events for ComboBox thats inside a dataGridView

Hi
How can i access the events of a comboBox that is inside
of a cell (on dataGridView)?

For example i have a dataGridView with one Row.
the first cell have a comboBox with "name", "date", and "age".
i need to make an event when i click "name" on the comboBox,
inside the second cell of the same row, will appear "paul".

thanks!!
JGLP  Tuesday, May 15, 2007 10:31 PM
A possible way: subscribe to EditingControlShowing event, cast the e.Control to a ComboBox and subscribe to it's SelectionChangeCommitted event... (sample code can be found in, (eg) http://www.timvw.be/exploring-datagridviewcomboboxcolumn-databinding-part2/ )

Another technique is to do something similar but it starts from the CellEnter event on the DataGridView (but i have yet to investigate that one))
timvw  Wednesday, May 16, 2007 5:41 AM
A possible way: subscribe to EditingControlShowing event, cast the e.Control to a ComboBox and subscribe to it's SelectionChangeCommitted event... (sample code can be found in, (eg) http://www.timvw.be/exploring-datagridviewcomboboxcolumn-databinding-part2/ )

Another technique is to do something similar but it starts from the CellEnter event on the DataGridView (but i have yet to investigate that one))
timvw  Wednesday, May 16, 2007 5:41 AM
Hi Tim, i didn't use your sugestion cause i started to use the Cell End Edit event, like
it was suggested on other forum. But now i have another problem, i think it's
easier, but i'm not getting to it...

I have two arrays:
array<String ^> ^name;
array<String ^> ^age;

name[0] = "paul";
name[1] = "john";
age[0] = "30";
age[
1] = "40";

And I have a dataGridView with multiple rows, and just two columns...
on column 1 I have a comboBox with:
this->option->Items->AddRange("name");
this->option->Items->AddRange("age");

on column2 i have an empty comboBox called res
And deppending on the choise of the first comboBox on column 1, i need
to add on the comboBox on column 2.

Example:
If i choose on comboBox thats on column1 the "name", on comboBox thats on
column2 need to appear the choises "paul" and "john".
If i choose "age", so the second comboBox need to be "30" and "40".

My question, is how can add strings on other comboBoxes looking first on
the previous comboBoxes (allways inside a dataGridView) ?

I have this code already:

[code]
private: System::Void dataGridView1_CellEndEdit(System:: Object^ sender, System::Windows::Forms:: DataGridViewCellEventArgs^ e) {
if(e->ColumnIndex == 1)
{
String^ s =dataGridView1->CurrentRow->Cells[0]->Value->ToString();
option->Items->Clear();
int line = e->RowIndex;
if(s=="name")
{
for(int i=0;i<name->Length;i++)
{
//this->res->Items->AddRange(name[ i ]);
/*this will write on all rows...i want to manipulate only the current row*/
}

}
else
if(s=="age")
{
for(int i=0;i<age->Length;i++)
{
//??? how can i write the age array on comboBox(column 2)?
}

}
}
}
[code]

thanks very much for the help
JGLP  Wednesday, May 16, 2007 7:22 PM

You can use google to search for other answers

Custom Search

More Threads

• Property Browser
• Copy Form Design to another Form or Application?
• Urgent for Tabindex in UserControl
• About Microsoft Express blend
• OnPaint firing in designer causing issues
• DataTreeGridView
• Draw Line Across controls.
• How to Create Sub property in C#.Net 2005
• Load problem
• User Control Bug with contained PictureBox Controls?