C
Cincy Steve
Guest
I am trying to implement a DataGridView in which ReadOnly cells are skipped when the user hits Tab or Right Arrow in the preceding cell (or Enter in the cell above).
My latest attempt uses a derived DataGridView in which I override one or more of the ProcessDialogKey, ProcessDataGridViewKey and ProcessCmdKey methods in order to detect Tab/Right/Enter and directly set the dgvs CurrentCell after searching past any ReadOnly cells. Setting the CurrentCell in these override methods causes the CellValidating event to be raised on the initial cell in which the user hit Tab/Right/Enter. This works fine when the data is valid, but when the data isnt valid (causing my event handler to show an error message in a MessageBox and then set e.Cancel = true before returning), I get an exception on the CurrentCell assignment statement saying “Operation did not succeed because the program cannot commit or quit a cell value change”.
I havent been able to find: (1) any way to trigger the CellValidating event before I try to set the CurrentCell in the ProcessXKey methods; or (2) any event that fires after the "next cell" processing triggered by the Tab/Right/Enter key that would let me change the CurrentCell then (i.e. after the CellValidating has been fully completed).
It doesn’t seem like this should be an atypical need or one that requires these brute force workarounds. Am I missing something that I’m not seeing in all the posts I’ve read on trying to control DataGridView behavior like this?
Thanks. Steve
Continue reading...
My latest attempt uses a derived DataGridView in which I override one or more of the ProcessDialogKey, ProcessDataGridViewKey and ProcessCmdKey methods in order to detect Tab/Right/Enter and directly set the dgvs CurrentCell after searching past any ReadOnly cells. Setting the CurrentCell in these override methods causes the CellValidating event to be raised on the initial cell in which the user hit Tab/Right/Enter. This works fine when the data is valid, but when the data isnt valid (causing my event handler to show an error message in a MessageBox and then set e.Cancel = true before returning), I get an exception on the CurrentCell assignment statement saying “Operation did not succeed because the program cannot commit or quit a cell value change”.
I havent been able to find: (1) any way to trigger the CellValidating event before I try to set the CurrentCell in the ProcessXKey methods; or (2) any event that fires after the "next cell" processing triggered by the Tab/Right/Enter key that would let me change the CurrentCell then (i.e. after the CellValidating has been fully completed).
It doesn’t seem like this should be an atypical need or one that requires these brute force workarounds. Am I missing something that I’m not seeing in all the posts I’ve read on trying to control DataGridView behavior like this?
Thanks. Steve
Continue reading...