Validating a DataGridViewComboBoxCell on focus lost

  • Thread starter Thread starter Nomasnd
  • Start date Start date
N

Nomasnd

Hi, i would like to make a DataGridViewComboBoxCell (which often is the
last-edited one) validate in such a way that when the datagrid lost the
focus the ComboBox cell Text property is setted to the combobox Value
property. I've already written all the code needed to change the
ComboBox view from a only-pushbutton style to a combobox style (with
the text box editable i mean) and to add the Text value to the ComboBox
Items and then setting the Value property of the ComboBox to the
original Text value. But all works correctly only if i change the
focus from the ComboBox cell to another cell. Instead if i click a
button outside the DataGridView the cell is not validated and so the
Value is not setted and remains null.

Is there a way to cause the validation of the DataGridView (and of the
ComboBox cell as well) when the DataGridView lost focus?

thanks
 
Nomasnd ha scritto:
Hi, i would like to make a DataGridViewComboBoxCell (which often is the
last-edited one) validate in such a way that when the datagrid lost the
focus the ComboBox cell Text property is setted to the combobox Value
property. I've already written all the code needed to change the
ComboBox view from a only-pushbutton style to a combobox style (with
the text box editable i mean) and to add the Text value to the ComboBox
Items and then setting the Value property of the ComboBox to the
original Text value. But all works correctly only if i change the
focus from the ComboBox cell to another cell. Instead if i click a
button outside the DataGridView the cell is not validated and so the
Value is not setted and remains null.

Is there a way to cause the validation of the DataGridView (and of the
ComboBox cell as well) when the DataGridView lost focus?

thanks

i found a way to do it.

Simply put code logic in the DataGridView.Leave event in which you must
do the actions said before (adding the edited value to the items and
then setting the ComboBox value) using the value returned by

DataGridView.CurrentCell.GetEditedFormattedValue

It worked for me
 
Nomasnd ha scritto:


i found a way to do it.

Simply put code logic in the DataGridView.Leave event in which you must
do the actions said before (adding the edited value to the items and
then setting the ComboBox value) using the value returned by

In my experience it doesn't really work..

(1) Add a row to the grid
(2) In one ComboBoxColumn choose a value, in another choose choose nothing.
(3) Select a different page by clicking on a TabControl. (Validation is triggered the Cancel property is set.
(4) Click again on the TabControl to select that other page. Validation isn't performed anymore...
But the grid still has an invalid row :(

My only workaround for now is to ignore the validation events, and do the
validation myself on the selecting event of the TabControl.
 
Back
Top