Reputation: 869
I am trying to create an application which outputs a simple text file. This is my first project in c#. I have created a data grid table. There are basically 5 cells in each row ,and the rows are added dynamically after the user input. User can change values in 2 of the 5 cells only. My problem lies here, In the third cell user has to select a value from combo box in cell 3, the values in cell 4 and 5 are to be populated after the value in combo box is selected. However I am unable to do that. Attached is the image for reference.
Upvotes: 0
Views: 881
Reputation: 63317
You can try something like this:
//EditingControlShowing event handler for your dataGridView1
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e){
ComboBox combo = e.Control as ComboBox;
if(combo != null) combo.SelectedIndexChanged += GridComboSelectedIndexChanged;
}
private void GridComboSelectedIndexChanged(object sender, EventArgs e) {
ComboBox combo = sender as ComboBox;
//Your populating code here
//you can access the selected index via combo.SelectedIndex
//you can access the current row by dataGridView1.CurrentCell.OwningRow
//then you can access to the cell 4 and cell 5 by dataGridView.CurrentCell.OwningRow.Cells[4] and dataGridView.CurrentCell.OwningRow.Cells[5]
}
Upvotes: 2