PC Review


Reply
Thread Tools Rate Thread

Datagrid and focus confusion

 
 
Bill C.
Guest
Posts: n/a
 
      10th Nov 2003
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
 
Reply With Quote
 
 
 
 
Nataliya
Guest
Posts: n/a
 
      11th Nov 2003
Hi,
ComboBox in a datagrid is something I was looking for as
well and after I've done some Internet research I found
that the best place to go for your answers is here:

http://www.syncfusion.com/FAQ/WinFor...c44c.asp#q480q

I strongly recommend this website.
It is very useful.
Do you want to implement databound combo or just fill
using .Add.Item method?

for both versions there is an answer. However, personally
I did not need either of them but something in between.
So, based on the samples in the article I've developed a
combo box that is bound but not using the ID for selection.
Anyway, if you need help let me know. I'll be happy to
help.

Sincerely,
Nataliya

>-----Original Message-----
>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
>.
>

 
Reply With Quote
 
Dmitriy Lapshin [C# / .NET MVP]
Guest
Posts: n/a
 
      11th Nov 2003
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." <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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


 
Reply With Quote
 
Dmitriy Lapshin [C# / .NET MVP]
Guest
Posts: n/a
 
      9th Dec 2003
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Not a very helpful comment. Can we get a link to these samples please!
>
> "Dmitriy Lapshin [C# / .NET MVP]" <x-(E-Mail Removed)> wrote
> in message news:O5r$(E-Mail Removed)...
> > 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." <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > 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

> >

>
>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
form focus confusion mark kubicki Microsoft Access Form Coding 1 27th Apr 2007 09:50 PM
datagrid confusion =?Utf-8?B?Q2hhcmxlc0E=?= Microsoft ASP .NET 0 16th Mar 2006 01:46 PM
Datagrid focus or lack of focus =?Utf-8?B?S3JlYXRpdmVLYWk=?= Microsoft Dot NET 0 26th Jan 2006 08:22 PM
dataGrid confusion Guy Noir Microsoft C# .NET 1 25th Jul 2005 04:28 PM
Datagrid and focus confusion Bill C. Microsoft C# .NET 2 9th Dec 2003 11:24 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:14 PM.