views:

2690

answers:

1

I have a ComboBox inside of a cell of a DataGridView Row on a Windows form. I need the following to happen:

  1. click on the ComboBox
  2. pick a value
  3. recalculate a total & display inside of a lable that is sitting outside of the DataGridView.

Currently, the following is happening:

  1. Click on the ComboBox
  2. Click it again to open the CB's Drop-down list
  3. select a value
  4. click outside of the cell to force a recalculation of the external label.

I want to avoid, first, having to click the combo twice (once to set focus, and again to select the value). Second, I'd like for a live recalculation to happen after selecting a value.

Does anyone have a trick or two to solve any of these?

I've tried most of the events on the DGV without much luck.

+3  A: 

Add a handler to the CellClick event of the DataGridView that looks a bit like:

private void vehicleTypeGridView_CellClick(object sender, DataGridViewCellEventArgs e)
{
    if ( e.RowIndex == - 1 ) return; //Header Cell clicked -> ignore it.
    vehicleTypeGridView.BeginEdit ( true );
    var control = vehicleTypeGridView.EditingControl as DataGridViewComboBoxEditingControl;
    if ( control != null ) control.DroppedDown = true;
}
David Kemp