DataGridView Cell Edit

  • Thread starter Thread starter bemanian
  • Start date Start date
B

bemanian

Hi,

This is a simple DataGridView in a windows form which contains a number
of other controls as buttons, text boxes and so on. The problem is when
the data grid cell editing is conducted via the entries by the
keyboard, combined by entries via the other control buttons (within the
win-form). It seems pressing any other control within the form suspends
the cell editing, expectedly. Then the insertion of the characters into
the cell via the other buttons would erase the entire cell content and
start the process all over again. Everything continues then on, even if
the key entries are attempted, until you use the character insertions
via the form buttons.

This is due to selection of the entire cell content and change of
selectstart property to zero, when the switch from keyboard to form
entries take place. Not a big deal if the metrics are captured via an
event, and reestablished prior to the form control entries? The problem
is using either EndEdit or Parsing events for the data grid, show the
SelectionLength and SelectionStart as full text length and zero
respectively (full text selection by the framework, and move of the
cursor to the start of the text content), and there is no event to be
utilized as the key entries into the grid cell is performed. Any idea!

Regards,

Reza Bemanian
 
Hi Reza,

You did a valiant job of trying to describe your problem, but I'm still not
sure I understand it. It seems you left a few details out. In particular,
what did you mean by "the insertion of the characters into the cell via the
other buttons would erase the entire cell content and start the process all
over again"? What other buttons are you talking about? Are you saying that
DataGridViewCell contents can be edited by using other Controls on the form?
If so, how is this achieved? For example, how do the other Controls know
which Cell you're editing, and what is already in it? Also, any time the
user is editing the cell using keyboard input, and the focus leaves the
DataGridView, the cell itself should validate and EndEdit (etc) on the cell
should be called. There is no guarantee that the user will use any other
Controls at this point. So, can you fill in the blanks?

--
HTH,

Kevin Spencer
Microsoft MVP
Bit Player
http://unclechutney.blogspot.com

Where there's a Will, there's a William.
 
Hello Kevin,

Thanks so much for the reply. I think you nailed the problem right on
the head. Knowing loosing the focus causes the cell edit to end, and
trying to capture SelectStart and SelectLength properties via the
EndEdit event, at leat was not working as expected in this case. The
event gets fired, but then I read zero for the start index, and the
string length for the SelectLength. This way I would not be able to
resume the edit as terminated.

Realizing it is an event race problem, have tried to use both the
Parsing and Formatting events, which provided almost similar outcomes
with some variations. Also, I tried to use the data grid KeyDown,
KeyPress, and KeyUp events to capture the keyboard entries while the
cell edit is in progress. This way simply by tracking the string buffer
manually, I should be able to resume a suspended cell edit with no
difficulty. The problem is these events only fire if a row, or a column
is selected (highlighted), and not when the cell edit is in progress.

It seems simply having an event to track the keyboard entties while
editing a cell would resolve this. I certainly apologize if my initial
description is not verbose enough, and hope this could further clarify
this matter.

Regards,
Reza Bemanian
 
Back
Top