Ok... I have written a custom control, it's a numberpad that dispatches an event when one of its buttons are clicked and supplies the KeyChar that was clicked (it's 0->9 and '.', but can support any character if needed).
I also have a custom Form type called 'AbstractDMWindowForm' and extends System.Windows.Forms.Form. It is used as the base class of any Forms in our project. It implements some common code that all our forms use. One of them is it watches the LostFocus event of all the children controls of itself and remembers which was the last control to have focus before the current one. I can then easily access a property 'LastActiveControl' to find out which control it was. Very useful for several things...
One of those useful things is combining it with the numberpad for an onscreen keyboard (meant for a touch screen). When I click on the number pad and receive the event I use SendKeys to emulate a keyboard keypress. But I want that text to go into the control that was last active, and clicking the numpad steals focus. So I set focus back to that 'LastActiveControl', then send the key stroke.
Private Sub pad_Numpad_Input(ByVal sender As Object, ByVal e As Controls.NumpadInputEventArgs) _bIsNumpadTyping = True If Me.LastActiveChildControl IsNot Nothing Then Me.LastActiveChildControl.Focus() End If SendKeys.Send(e.Keys) _bIsNumpadTyping = False End Sub
Now this works wonderfully for most Controls that can be typed in (ComboBox, TextBox, etc). But one it has a total bitch with (and I hate the damn thing in general, but we use it a lot in the project), and that is the DataGridView with text cells.
What happens is when I return focus to the DataGridView the last cell was selected is still the selected cell. That's good, that's what I expected. BUT now all the text in the cell is selected... ? I'd like to stop this, but don't know exactly how I should go about it.
The only idea I have so far is to check if the LastActiveChildControl is a DataGridView and that it has a selected cell, and if that cell is a text cell and is activated for edit, then we ensure that it's not SelectAll.
But I find this dirty AND it removes support for AllSelect and typing on the numpad (what if the user did select all the text and now expects this key stroke to replace the whole thing...).
This post has been edited by lordofduct: 22 October 2010 - 08:18 AM