So I checked the .Net framework forum, and there was no 'general' section, nor was there a 'Windows.Forms' section (but there was a WPF section...). I attempted posting a similar question to this post in the VB.Net forum, with no assistance. The only reason is because the job is in VB. But really the question I have is not really VB dependent and is a .Net issue. Because I prefer C# over VB, and most of the skilled .Net users I've seen around the forum seem to also prefer C#, I'm going to post this here.
My Question:
So I have a simple on screen keyboard control. It's just a custom Control with a bunch of buttons laid out like a Numpad. When it's clicked I use SendKeys to simulate a key press of that number. Of course when the user presses each button, the focus is given to the button being clicked and I need to manually return it back to the control that had the focus prior. I do this by listening to the leave event of all controls I considered 'managed' and remember the last one that had focus, and return said focus.
Rather simple.
When returning focus these controls generally remember the state of their selection if they were (if a TextBox it remembers what, if any, text was highlighted by the user. And where the input carriage belongs).
But one stupid Control type gives me a giant pain in the arse.
DataGridView
The DataGridView as I've come to learn (keep in mind I come from other languages, then to mono, and now to actual .Net and only recently started playing with the Windows.Forms namespace... I hate it, sorry), it uses a smart little method of reducing memory required by the Control. When you go to edit any cell an 'EditingControl' is created for the cell temporarily, then once the cell is left and validated, that 'EditingControl' is disposed of in some manner. Smart in some respects, but deals one majour blow to my system.
When leaving the DataGridView that is being edited mode to strike this button and returning back to the DataGridView, the EditingControl had been disposed of and doesn't remember its state. Calling 'Focus' brings it back into focus, and the cell is in edit more (because the DataGridView remembers), but the cell itself is in a default selected mode (for a text cell the text is all highlighted, not good if we want subsequent key strikes).
With some hacking a work mate of mine found different ways to deal with it. All of them hacky, and none of them really working out exactly how we hope.
The best one he found was when leaving a Control we check if it is a DataGridView, set the forms active control to the 'EditingControl' (yeah, that's the super hacky part I hate, but it keeps it from getting disposed), then when the button for the numpad is clicked we check if the last control was a DataGridView or not, if not we call Focus, if is we call BeginEdit.
But as one would suspect this hack causes the 'EditingControl' to get stuck on screen, as I expected something of the likes to occur.
So I ask of you guys, do you have any experience with this one hell of an annoying Control, this problem, and have any ideas how to deal with it?
The specific functionality we expect is that when we return focus to the last active control before hitting the numpad, that the selected/highlighted state of the control is how it was when we left. All controls accept for DataGridView act as expected... but editable DataGridViews play a huge role in the project.
This post has been edited by lordofduct: 02 November 2010 - 08:12 AM

New Topic/Question
Reply




MultiQuote







|