Home » C++ ProgrammingRSS

how to make selectedIndexChange Event for ComboBox that inside tha DataGridView and How to store the

Hi Friendz......

how to make SelectedIndexChanged Event for Combo Box that inside the DataGridView and How to store the value of DataGridView ComboBox to database?

Plaese anybody help me .....

 

thank You

 

Faisal.A

 

4 Answers Found

 

Answer 1

Use  CellValueChanged event  in your dataGridView as follows
 private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
    {
      if (e.ColumnIndex == 0 && e.RowIndex >= 0) // check the evenet occured form you combo  column
      {
        // read the value
        object newValue = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
      }
    }
 

Answer 2

Hi,

Please refer the code given below.

private void CreateDataGridView()
{
DataGridView dataGridView = new DataGridView();
dataGridView.EditingControlShowing+=new DataGridViewEditingControlShowingEventHandler(dataGridView_EditingControlShowing);
}

private void dataGridView_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
  ComboBox comboBox = e.Control as ComboBox; 
  
  comboBox.SelectedIndexChanged += new EventHandler(comboBox_SelectedIndexChanged); 

}

private void comboBox_SelectedIndexChanged(object sender, EventArgs e) 
 { 
   int selectedIndex = ((ComboBox)sender).SelectedIndex; 
   MessageBox.Show("Selected Index = " + selectedIndex);
}
 

Answer 3

that is not working.......

What i want to do here, there is two combobox  in my datagridview  .

if i change the value of first combo  box , the second combo box  value should be changed....

here, i need the selected index changed event.

how to do that event?

thanks

Faisal.A

 

 

 

Answer 4

Hi, I have modified the code. By using this code you will get the selected index of combobox  column

Private void CreateDataGrid()
{
 DataGridView dataGridView = new DataGridView(); DataGridViewComboBoxColumn col = new DataGridViewComboBoxColumn(); col.DisplayStyle = DataGridViewComboBoxDisplayStyle.DropDownButton; col.Items.AddRange("1", "2", "3"); DataGridViewComboBoxColumn col2 = new DataGridViewComboBoxColumn(); col2.DisplayStyle = DataGridViewComboBoxDisplayStyle.DropDownButton; col2.Items.AddRange("4", "5", "6"); dataGridView.Columns.AddRange(col,col2); dataGridView.EditingControlShowing+=new DataGridViewEditingControlShowingEventHandler(dataGridView1_EditingControlShowing); 
} 

void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) 
{ 
ComboBox comboBox = e.Control as ComboBox; comboBox.SelectedIndexChanged += new EventHandler(comboBox_SelectedIndexChanged);
 } 

private void comboBox_SelectedIndexChanged(object sender, EventArgs e)
 { 
int selectedIndex = ((ComboBox)sender).SelectedIndex; MessageBox.Show("Selected Index = " + selectedIndex);
 }
 
 
 

<< Previous      Next >>


Microsoft   |   Windows   |   Visual Studio   |   Follow us on Twitter