468,769 Members | 2,280 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,769 developers. It's quick & easy.

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 2263
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by raj | last post: by
5 posts views Thread by Bryan Masephol | last post: by
3 posts views Thread by bardo | last post: by
2 posts views Thread by kenglish_hi | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.