472,958 Members | 2,286 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

Datagrid and focus confusion

Hi,

I'm trying to implement a ComboBox drop-down column for a DataGrid.
When a cell is selected in the ComboBox column I overlay a ComboBox
over the cell and call:

this.comboBox.Show();
this.comboBox.BringToFront();
this.comboBox.Focus();

Now when I press the up/down arrow keys I would expect the ComboBox
to respond to those keyboard inputs because it has the focus. But
it doesn't. Somehow the DataGrid gets the key strokes and causes
the next row in the DataGrid to be selected.

Why would this be? I'm positive the ComboBox has the focus. I
added event handlers for the DataGrid enter/leave, and the ComboBox
enter/leave events and I only see the ComboBox ones getting called.

This is really annoying. The only workaround I've found is to
derive a class from ComboBox that overrides the WndProc and
ProcessCmdKey methods and catches the keystrokes and tries to
do the correct thing. But this has problems because then I have
to catch everything (Enter, Tab, Shift-tab, Left, Right, etc.).

Now I'm having a problem processing Enter correctly. When the
ComboBox drop down list is displayed I can now go up and down
the list using the arrow keys but the only way I can correctly
select one is with the mouse. When I try to use the enter key
nothing happens because I've overridden its behavior and I'm
not sure what methods to call to make it work correctly (i.e.
commit the current choice and collapse the menu again).

I don't understand why the ComboBox isn't handling these things
automatically if it has the focus.

Any help appreciated. Thanks,

Bill
Nov 15 '05 #1
2 2446
Hi Bill,

This is the wrong way of implementing a custom column. You have probably
been inspired by an example once published by Microsoft. I don't know why on
Earth such an inconvenient way of doing things was suggested in that
example, but you should definitely avoid that and refer to recent MSDN
articles on implementing custom DataGridColumnStyles which are actually the
only right way to customize the DataGrid.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Bill C." <bi***********@yahoo.com> wrote in message
news:1e**************************@posting.google.c om...
Hi,

I'm trying to implement a ComboBox drop-down column for a DataGrid.
When a cell is selected in the ComboBox column I overlay a ComboBox
over the cell and call:

this.comboBox.Show();
this.comboBox.BringToFront();
this.comboBox.Focus();

Now when I press the up/down arrow keys I would expect the ComboBox
to respond to those keyboard inputs because it has the focus. But
it doesn't. Somehow the DataGrid gets the key strokes and causes
the next row in the DataGrid to be selected.

Why would this be? I'm positive the ComboBox has the focus. I
added event handlers for the DataGrid enter/leave, and the ComboBox
enter/leave events and I only see the ComboBox ones getting called.

This is really annoying. The only workaround I've found is to
derive a class from ComboBox that overrides the WndProc and
ProcessCmdKey methods and catches the keystrokes and tries to
do the correct thing. But this has problems because then I have
to catch everything (Enter, Tab, Shift-tab, Left, Right, etc.).

Now I'm having a problem processing Enter correctly. When the
ComboBox drop down list is displayed I can now go up and down
the list using the arrow keys but the only way I can correctly
select one is with the mouse. When I try to use the enter key
nothing happens because I've overridden its behavior and I'm
not sure what methods to call to make it work correctly (i.e.
commit the current choice and collapse the menu again).

I don't understand why the ComboBox isn't handling these things
automatically if it has the focus.

Any help appreciated. Thanks,

Bill


Nov 15 '05 #2
Keith,

Here are the links (mind the line wraps):

http://msdn.microsoft.com/msdnmag/is...asp?frame=true
http://msdn.microsoft.com/library/en...asp?frame=true
http://msdn.microsoft.com/library/en...asp?frame=true
--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Keith Lubell" <kl*****@mindspring.com> wrote in message
news:eG**************@tk2msftngp13.phx.gbl...
Not a very helpful comment. Can we get a link to these samples please!

"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> wrote
in message news:O5*************@TK2MSFTNGP11.phx.gbl...
Hi Bill,

This is the wrong way of implementing a custom column. You have probably
been inspired by an example once published by Microsoft. I don't know
why on
Earth such an inconvenient way of doing things was suggested in that
example, but you should definitely avoid that and refer to recent MSDN
articles on implementing custom DataGridColumnStyles which are actually

the
only right way to customize the DataGrid.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Bill C." <bi***********@yahoo.com> wrote in message
news:1e**************************@posting.google.c om...
Hi,

I'm trying to implement a ComboBox drop-down column for a DataGrid.
When a cell is selected in the ComboBox column I overlay a ComboBox
over the cell and call:

this.comboBox.Show();
this.comboBox.BringToFront();
this.comboBox.Focus();

Now when I press the up/down arrow keys I would expect the ComboBox
to respond to those keyboard inputs because it has the focus. But
it doesn't. Somehow the DataGrid gets the key strokes and causes
the next row in the DataGrid to be selected.

Why would this be? I'm positive the ComboBox has the focus. I
added event handlers for the DataGrid enter/leave, and the ComboBox
enter/leave events and I only see the ComboBox ones getting called.

This is really annoying. The only workaround I've found is to
derive a class from ComboBox that overrides the WndProc and
ProcessCmdKey methods and catches the keystrokes and tries to
do the correct thing. But this has problems because then I have
to catch everything (Enter, Tab, Shift-tab, Left, Right, etc.).

Now I'm having a problem processing Enter correctly. When the
ComboBox drop down list is displayed I can now go up and down
the list using the arrow keys but the only way I can correctly
select one is with the mouse. When I try to use the enter key
nothing happens because I've overridden its behavior and I'm
not sure what methods to call to make it work correctly (i.e.
commit the current choice and collapse the menu again).

I don't understand why the ComboBox isn't handling these things
automatically if it has the focus.

Any help appreciated. Thanks,

Bill



Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: raj | last post by:
Hi, The focus in the datagrid is not lost even after leaving the datagrid. The selected cell is highlighted even when the focus from the datagrid is lost. This happens only after the .NET...
0
by: ED M. | last post by:
Hello all...I'm new to the board. I have a problem that I hope someone here might be able to solve for me. I am doing some clientside validation using Javascript. The text I am testing is...
11
by: Junkguy | last post by:
I need some help programmatically causing a row in a DataGrid to "flush" its contents to its bound data (in Visual Studio 6 using Windows Forms with C#). My issue is I want to send an update to...
5
by: Bryan Masephol | last post by:
Hi All I got a datagrid and a ComboBox on a form. I populate the combobox with years for all the data avaiable. When the user chooses a year the datagrid is populated with the specific years...
0
by: Shravan | last post by:
Hi, I have a Windows Forms Custom DataGrid, which is put in a usercontrol, which on setting DataSource is setting focus to grid. The call stack for setting the focus is as follows. This is not...
3
by: bardo | last post by:
I have a Datagrid that is inside a panel. I want to use the keyDown event to reconize the arrow keys. But I have no luck at all. The problem is that the keydown event won't fire at all, unless I...
1
by: jimb | last post by:
I can get the dropdownlist into the datagrid, and I can populate it, but I can't read it. Anybody have a working example of a dropdownlist in an editable grid? Thanks. -- .....
2
by: kenglish_hi | last post by:
hello, I have a form with a datagrid and combo box. When the form loads up, i want the focus to be on the combo box. however, whenever it loads up, the focus is always on the datagrid. in the...
21
by: Sharon | last post by:
I have added an auto scroll feature to my DataGrid control like this: private void DoAutoScroll() { DataView dv = m_DataGrid.DataSource as DataView; DataGridCell cell = m_DataGrid.CurrentCell;...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.