473,405 Members | 2,354 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

DataGrid ComboBox

Hi I am still having problems with Tabbing through a DataGrid with a
DataGridComboBox Column.

I need to allow the User to Type the value into the ComboBox so consequently
its ComboBoxStyle is set to DropDown. This causes the Tabbing to work
incorrectly. Even though I am consuming the Windows Message WM_KEYUP, it
still Tabs through the ComboBox Column on to the next Column.

I found if I do not give the keyboard focus ie remark out
ColumnComboBox.Focus the Tabbing works correctly but the ComboBox doesn't.

I tried delaying the sending of the WM_SETFOCUS Message but that didn't work
either.

Can anyone think of a workaround for this or even another way to give the
user similar Functionality. They want to type the value in using the
keyboard but the values are fixed so I have been using the Validating Event
to ensure that they are values from the Combos list. And it helps them to
see the values as in the Combos DropDown.

Any thoughts appreciated.

Doug
Mar 19 '07 #1
10 2007
Try using PreProcessMessage to ignore the KEYUP instead of WndProc.

Public Overrides Function PreProcessMessage(ByRef msg As
System.Windows.Forms.Message) As Boolean
If msg.Msg = WM_KEYUP Then
Return True
End If
Return MyBase.PreProcessMessage(msg)
End Function

===================
Clay Burch
Syncfusion, Inc.

Mar 19 '07 #2
Clay,
Again thanks for your input.

To use "PreProcessMessage" will I have to derive my DataGrid?

Doug

"ClayB" <cl***@syncfusion.comwrote in message
news:11**********************@d57g2000hsg.googlegr oups.com...
Try using PreProcessMessage to ignore the KEYUP instead of WndProc.

Public Overrides Function PreProcessMessage(ByRef msg As
System.Windows.Forms.Message) As Boolean
If msg.Msg = WM_KEYUP Then
Return True
End If
Return MyBase.PreProcessMessage(msg)
End Function

===================
Clay Burch
Syncfusion, Inc.

Mar 19 '07 #3
I get an Error
"'Function PreProcessMessage' can not be declared 'Overrides' because it
does not override a function in the base class"

Am I missing something?

Doug
Mar 19 '07 #4
PreProcessMessage is a virtual member of Control. Here is a msdn help
link on it.

http://msdn.microsoft.com/library/de...ssagetopic.asp

Here is a link to the previous sample with code added.

http://www.syncfusion.com/Support/us...o_506da9b0.zip

===========================
Clay Burch
Syncfusion, Inc.
Mar 19 '07 #5
Clay,

You are a lifesaver.

I owe you a few beers if you get to Sydney.

Thanks,

Doug
Mar 19 '07 #6
Doug,

I had similar problem about half a year ago, and had it solved in a similar
way. I have extended the concept slightly - you may find it useful as well:

Private Sub moveIndex(ByVal count As Integer, ByVal moveDown As Boolean,
ByVal offset As Integer)
Dim origIndex As Integer = Me.SelectedIndex
Dim newIndex As Integer
If moveDown Then
Dim maxIndex As Integer = count - 1
If origIndex < maxIndex Then
newIndex = Math.Min(origIndex + offset, maxIndex)
Else
newIndex = origIndex
End If
ElseIf origIndex 0 Then
newIndex = Math.Max(origIndex - offset, 0)
End If
If newIndex <origIndex Then
Me.SelectedIndex = newIndex
If Not _startEditing Is Nothing Then
_startEditing(Me, System.EventArgs.Empty)
End If
End If
End Sub

Public Overrides Function PreProcessMessage(ByRef msg As
System.Windows.Forms.Message) As Boolean
Dim keyCode As Keys = CType((msg.WParam.ToInt32 And Keys.KeyCode), Keys)
Dim baseProcess As Boolean = True
If msg.Msg = _WM_KEYDOWN Then
Select Case keyCode
Case Keys.Up, Keys.Down, Keys.PageUp, Keys.PageDown
baseProcess = False
Dim count As Integer = Me.Items.Count
If count 0 Then
Select Case keyCode
Case Keys.Up
moveIndex(count, False, 1)
Case Keys.Down
moveIndex(count, True, 1)
Case Else
Dim pageCount As Integer = Me.MaxDropDownItems
If keyCode = Keys.PageUp Then
moveIndex(count, False, pageCount)
ElseIf keyCode = Keys.PageDown Then
moveIndex(count, True, pageCount)
End If
End Select
End If
End Select
End If
Dim result As Boolean = True
If baseProcess Then
result = MyBase.PreProcessMessage(msg)
End If
Return result
End Function

Placing the above code inside the combo allows it to react to the navigation
button events

HTH

"Doug Bell" wrote:
Clay,

You are a lifesaver.

I owe you a few beers if you get to Sydney.

Thanks,

Doug
Mar 20 '07 #7
Hi Thanks Sergey,
I took my project in yesterday for "Show and Tell" and the combo Navigation
was one of their next requests.
(I should have put a functional specification together)
I was going to try to try and work out a solution this morning so perfect
timing
..
Can you explain your "_startEditing" ?

The Code I have is pretty much based on Clay's example.

What is your _startEditing ?

Thanks

Doug


"Sergey Poberezovskiy" <Se*****************@discussions.microsoft.comwrot e
in message news:A0**********************************@microsof t.com...
Doug,

I had similar problem about half a year ago, and had it solved in a
similar
way. I have extended the concept slightly - you may find it useful as
well:
>
Private Sub moveIndex(ByVal count As Integer, ByVal moveDown As Boolean,
ByVal offset As Integer)
Dim origIndex As Integer = Me.SelectedIndex
Dim newIndex As Integer
If moveDown Then
Dim maxIndex As Integer = count - 1
If origIndex < maxIndex Then
newIndex = Math.Min(origIndex + offset, maxIndex)
Else
newIndex = origIndex
End If
ElseIf origIndex 0 Then
newIndex = Math.Max(origIndex - offset, 0)
End If
If newIndex <origIndex Then
Me.SelectedIndex = newIndex
If Not _startEditing Is Nothing Then
_startEditing(Me, System.EventArgs.Empty)
End If
End If
End Sub

Public Overrides Function PreProcessMessage(ByRef msg As
System.Windows.Forms.Message) As Boolean
Dim keyCode As Keys = CType((msg.WParam.ToInt32 And Keys.KeyCode), Keys)
Dim baseProcess As Boolean = True
If msg.Msg = _WM_KEYDOWN Then
Select Case keyCode
Case Keys.Up, Keys.Down, Keys.PageUp, Keys.PageDown
baseProcess = False
Dim count As Integer = Me.Items.Count
If count 0 Then
Select Case keyCode
Case Keys.Up
moveIndex(count, False, 1)
Case Keys.Down
moveIndex(count, True, 1)
Case Else
Dim pageCount As Integer = Me.MaxDropDownItems
If keyCode = Keys.PageUp Then
moveIndex(count, False, pageCount)
ElseIf keyCode = Keys.PageDown Then
moveIndex(count, True, pageCount)
End If
End Select
End If
End Select
End If
Dim result As Boolean = True
If baseProcess Then
result = MyBase.PreProcessMessage(msg)
End If
Return result
End Function

Placing the above code inside the combo allows it to react to the
navigation
button events

HTH

"Doug Bell" wrote:
Clay,

You are a lifesaver.

I owe you a few beers if you get to Sydney.

Thanks,

Doug


Mar 20 '07 #8
Sergey, to clarify,
I have the navigation keys working with your extra code but I just wondered
what your
"startEditing" was doing?

Doug
"Sergey Poberezovskiy" <Se*****************@discussions.microsoft.comwrot e
in message news:A0**********************************@microsof t.com...
Doug,

I had similar problem about half a year ago, and had it solved in a
similar
way. I have extended the concept slightly - you may find it useful as
well:
>
Private Sub moveIndex(ByVal count As Integer, ByVal moveDown As Boolean,
ByVal offset As Integer)
Dim origIndex As Integer = Me.SelectedIndex
Dim newIndex As Integer
If moveDown Then
Dim maxIndex As Integer = count - 1
If origIndex < maxIndex Then
newIndex = Math.Min(origIndex + offset, maxIndex)
Else
newIndex = origIndex
End If
ElseIf origIndex 0 Then
newIndex = Math.Max(origIndex - offset, 0)
End If
If newIndex <origIndex Then
Me.SelectedIndex = newIndex
If Not _startEditing Is Nothing Then
_startEditing(Me, System.EventArgs.Empty)
End If
End If
End Sub

Public Overrides Function PreProcessMessage(ByRef msg As
System.Windows.Forms.Message) As Boolean
Dim keyCode As Keys = CType((msg.WParam.ToInt32 And Keys.KeyCode), Keys)
Dim baseProcess As Boolean = True
If msg.Msg = _WM_KEYDOWN Then
Select Case keyCode
Case Keys.Up, Keys.Down, Keys.PageUp, Keys.PageDown
baseProcess = False
Dim count As Integer = Me.Items.Count
If count 0 Then
Select Case keyCode
Case Keys.Up
moveIndex(count, False, 1)
Case Keys.Down
moveIndex(count, True, 1)
Case Else
Dim pageCount As Integer = Me.MaxDropDownItems
If keyCode = Keys.PageUp Then
moveIndex(count, False, pageCount)
ElseIf keyCode = Keys.PageDown Then
moveIndex(count, True, pageCount)
End If
End Select
End If
End Select
End If
Dim result As Boolean = True
If baseProcess Then
result = MyBase.PreProcessMessage(msg)
End If
Return result
End Function

Placing the above code inside the combo allows it to react to the
navigation
button events

HTH

"Doug Bell" wrote:
Clay,

You are a lifesaver.

I owe you a few beers if you get to Sydney.

Thanks,

Doug


Mar 20 '07 #9
Doug,

_startEditing is a private variable that I initialise in the
comboconstructor - it refers to AddressOf selectionChangeCommit procedure in
DataGridComboboxColumn class.

Here is the constructor for the DataGridComboboxColumn:

Public Sub New()
' Create our own customized Combobox, which is used in the DataGrid
_cbo = New gridComboBox(AddressOf selectionChangeCommit)
_cbo.DropDownStyle = ComboBoxStyle.DropDownList
' GridComboBox subscribes to the Leave Event. It occurs when the
' input focus leaves the ComboBox.
AddHandler _cbo.Leave, AddressOf leaveComboBox
' GridComboBox subscribes to the SelectionChangeCommitted Event.
' It occurs when the selected item has changed and that change
' is committed (save the changed data to the DataGrid TextBox).
AddHandler _cbo.SelectionChangeCommitted, AddressOf selectionChangeCommit
End Sub

Now the actual procedure:
' The ColumnStartedEditing method allows the DataGrid
' to show a pencil in the row header indicating the row
' is being edited. (base is the parent DataGridTextBoxColumn)
Private Sub selectionChangeCommit(ByVal sender As System.Object, ByVal e As
System.EventArgs)
_editing = True
MyBase.ColumnStartedEditing(CType(sender, Control))
End Sub
And leave procedure:
' Handle Combobox Behaviour when Focus leaves the Combobox.
Private Sub leaveComboBox(ByVal sender As System.Object, ByVal e As
System.EventArgs)
If _editing Then
' Set the Combobox ValueMember to the current RowColumn
' when the Focus leaves the Combobox.
SetColumnValueAtRow(_currencyManager, _rowNum, _cbo.Text)
_editing = False
' Redraws the column
Invalidate()
End If
' Hide the current Combobox when Focus on Combobox is lost
_cbo.Hide()
End Sub

I think that should cover most of it. My task was to create combobox display
different lists on different grid rows, so some of the code may not be
relevant, but it should not hurt either.

If the code above does not work or I have missed something again, let me know

Serge

"Doug Bell" wrote:
Sergey, to clarify,
I have the navigation keys working with your extra code but I just wondered
what your
"startEditing" was doing?

Doug
"Sergey Poberezovskiy" <Se*****************@discussions.microsoft.comwrot e
in message news:A0**********************************@microsof t.com...
Doug,

I had similar problem about half a year ago, and had it solved in a
similar
way. I have extended the concept slightly - you may find it useful as
well:

Private Sub moveIndex(ByVal count As Integer, ByVal moveDown As Boolean,
ByVal offset As Integer)
Dim origIndex As Integer = Me.SelectedIndex
Dim newIndex As Integer
If moveDown Then
Dim maxIndex As Integer = count - 1
If origIndex < maxIndex Then
newIndex = Math.Min(origIndex + offset, maxIndex)
Else
newIndex = origIndex
End If
ElseIf origIndex 0 Then
newIndex = Math.Max(origIndex - offset, 0)
End If
If newIndex <origIndex Then
Me.SelectedIndex = newIndex
If Not _startEditing Is Nothing Then
_startEditing(Me, System.EventArgs.Empty)
End If
End If
End Sub

Public Overrides Function PreProcessMessage(ByRef msg As
System.Windows.Forms.Message) As Boolean
Dim keyCode As Keys = CType((msg.WParam.ToInt32 And Keys.KeyCode), Keys)
Dim baseProcess As Boolean = True
If msg.Msg = _WM_KEYDOWN Then
Select Case keyCode
Case Keys.Up, Keys.Down, Keys.PageUp, Keys.PageDown
baseProcess = False
Dim count As Integer = Me.Items.Count
If count 0 Then
Select Case keyCode
Case Keys.Up
moveIndex(count, False, 1)
Case Keys.Down
moveIndex(count, True, 1)
Case Else
Dim pageCount As Integer = Me.MaxDropDownItems
If keyCode = Keys.PageUp Then
moveIndex(count, False, pageCount)
ElseIf keyCode = Keys.PageDown Then
moveIndex(count, True, pageCount)
End If
End Select
End If
End Select
End If
Dim result As Boolean = True
If baseProcess Then
result = MyBase.PreProcessMessage(msg)
End If
Return result
End Function

Placing the above code inside the combo allows it to react to the
navigation
button events

HTH

"Doug Bell" wrote:
Clay,
>
You are a lifesaver.
>
I owe you a few beers if you get to Sydney.
>
Thanks,
>
Doug
>
>
>


Mar 20 '07 #10
Thanks

Doug
"Sergey Poberezovskiy" <Se*****************@discussions.microsoft.comwrot e
in message news:92**********************************@microsof t.com...
Doug,

_startEditing is a private variable that I initialise in the
comboconstructor - it refers to AddressOf selectionChangeCommit procedure
in
DataGridComboboxColumn class.

Here is the constructor for the DataGridComboboxColumn:

Public Sub New()
' Create our own customized Combobox, which is used in the DataGrid
_cbo = New gridComboBox(AddressOf selectionChangeCommit)
_cbo.DropDownStyle = ComboBoxStyle.DropDownList
' GridComboBox subscribes to the Leave Event. It occurs when the
' input focus leaves the ComboBox.
AddHandler _cbo.Leave, AddressOf leaveComboBox
' GridComboBox subscribes to the SelectionChangeCommitted Event.
' It occurs when the selected item has changed and that change
' is committed (save the changed data to the DataGrid TextBox).
AddHandler _cbo.SelectionChangeCommitted, AddressOf selectionChangeCommit
End Sub

Now the actual procedure:
' The ColumnStartedEditing method allows the DataGrid
' to show a pencil in the row header indicating the row
' is being edited. (base is the parent DataGridTextBoxColumn)
Private Sub selectionChangeCommit(ByVal sender As System.Object, ByVal e
As
System.EventArgs)
_editing = True
MyBase.ColumnStartedEditing(CType(sender, Control))
End Sub
And leave procedure:
' Handle Combobox Behaviour when Focus leaves the Combobox.
Private Sub leaveComboBox(ByVal sender As System.Object, ByVal e As
System.EventArgs)
If _editing Then
' Set the Combobox ValueMember to the current RowColumn
' when the Focus leaves the Combobox.
SetColumnValueAtRow(_currencyManager, _rowNum, _cbo.Text)
_editing = False
' Redraws the column
Invalidate()
End If
' Hide the current Combobox when Focus on Combobox is lost
_cbo.Hide()
End Sub

I think that should cover most of it. My task was to create combobox
display
different lists on different grid rows, so some of the code may not be
relevant, but it should not hurt either.

If the code above does not work or I have missed something again, let me
know
>
Serge

"Doug Bell" wrote:
Sergey, to clarify,
I have the navigation keys working with your extra code but I just
wondered
what your
"startEditing" was doing?

Doug
"Sergey Poberezovskiy" <Se*****************@discussions.microsoft.com>
wrote
in message news:A0**********************************@microsof t.com...
Doug,
>
I had similar problem about half a year ago, and had it solved in a
similar
way. I have extended the concept slightly - you may find it useful as
well:
>
Private Sub moveIndex(ByVal count As Integer, ByVal moveDown As
Boolean,
ByVal offset As Integer)
Dim origIndex As Integer = Me.SelectedIndex
Dim newIndex As Integer
If moveDown Then
Dim maxIndex As Integer = count - 1
If origIndex < maxIndex Then
newIndex = Math.Min(origIndex + offset, maxIndex)
Else
newIndex = origIndex
End If
ElseIf origIndex 0 Then
newIndex = Math.Max(origIndex - offset, 0)
End If
If newIndex <origIndex Then
Me.SelectedIndex = newIndex
If Not _startEditing Is Nothing Then
_startEditing(Me, System.EventArgs.Empty)
End If
End If
End Sub
>
Public Overrides Function PreProcessMessage(ByRef msg As
System.Windows.Forms.Message) As Boolean
Dim keyCode As Keys = CType((msg.WParam.ToInt32 And Keys.KeyCode),
Keys)
Dim baseProcess As Boolean = True
If msg.Msg = _WM_KEYDOWN Then
Select Case keyCode
Case Keys.Up, Keys.Down, Keys.PageUp, Keys.PageDown
baseProcess = False
Dim count As Integer = Me.Items.Count
If count 0 Then
Select Case keyCode
Case Keys.Up
moveIndex(count, False, 1)
Case Keys.Down
moveIndex(count, True, 1)
Case Else
Dim pageCount As Integer = Me.MaxDropDownItems
If keyCode = Keys.PageUp Then
moveIndex(count, False, pageCount)
ElseIf keyCode = Keys.PageDown Then
moveIndex(count, True, pageCount)
End If
End Select
End If
End Select
End If
Dim result As Boolean = True
If baseProcess Then
result = MyBase.PreProcessMessage(msg)
End If
Return result
End Function
>
Placing the above code inside the combo allows it to react to the
navigation
button events
>
HTH
>
"Doug Bell" wrote:
>
Clay,

You are a lifesaver.

I owe you a few beers if you get to Sydney.

Thanks,

Doug


Mar 21 '07 #11

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

Similar topics

0
by: Gamze | last post by:
Hi, How can i get values from datagrid to combobox and should select the same name as in datagrid row on the combobox control In my vb.net windows application ,i have combobox which is...
3
by: Bill C. | last post by:
Hello, I know this has been discussed a lot already because I've been searching around for information the last few weeks. I'm trying to implement a DataGridComboBoxColumn class. I've found...
2
by: Bill C. | last post by:
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();...
3
by: Kevin | last post by:
Hi Al I want to add two combobox columns in my datagrid. the one combobox column must be bound to the same datasource that the datagrid is, and the other combobox I just want to populate with a...
3
by: PeterZ | last post by:
G'day, After doing much searching and pinching bits of ideas from here there and everywhere I came up with a fairly 'clean' solution of including a comboBox into a dataGrid column. You can...
2
by: pei_world | last post by:
I want to implement a key hit with enter to dropdown a combobox that is in the datagrid. in this case I need to override its original behaviours. I found some codes from the web. Does anyone know...
3
by: TT (Tom Tempelaere) | last post by:
Hay there, I'm writing my own DataGridComboBoxColumn because .NET 1.1 does not have one (I hope .NET 2.0 supplies one). I based it on this article:...
3
by: Doug | last post by:
Hi I have the following code (not mine) that populates a datagrid with some file names. But I want to replace the datagrid with a combo box. private void OnCurrentDataCellChanged(object sender,...
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. -- .....
4
by: Jan Nielsen | last post by:
Hi all I'm a former Access developer who would like to implement a many-to-many relation in about the same way you do in Access: With a subform and a combo box. Is it possible to use a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.