|
-
Mar 16th, 2018, 09:11 AM
#9
Re: DataGridView Events
 Originally Posted by jmcilhinney
A DataGridView contains no child controls by default. When you start editing a cell, an editing control is created and embedded in the cell. That is why you stop seeing events raised by the grid while you're editing: it's the editing control that is raising events. When the editing control is created, the Value of the cell is assigned to the appropriate property of the control, e.g. the Text of a TextBox. When the editing session ends, the control property is assigned back to the Value property of the cell. That's why you don't see a CellValueChanged event from the grid until you end the editing session, which is usually done by navigating to a different cell.
What you can do is handle the EditingControlShowing event of the grid to get access to the editing control. You can then attach the appropriate event handlers to it. For instance, if you need to process keyboard input when editing a text box cell, you can attach handlers for KeyDown and/or KeyUp and/or KeyPress of the TextBox editing control. You can then handle the CellEndEdit event of the grid to detach those event handlers.
I did not know that. That's the solution that had to be used in VB6 because the MSFlexGrid was read only. You had to do it yourself, though. When the user clicked on the cell, you moved and sized a textbox to the size and location of the cell, then copied the cell contents into the textbox. If you did it right, the user never knew they weren't editing in the cell. MS formalized that approach for the DGV, though they also extended it a bit.
My usual boring signature: Nothing
 
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|