Ok Simple problem.

I have a MS datagrid I made my very own multiline
columnstyle for my datagrid. Right away I had problems.
Yea it was multiline (using a regular textbox that shows
up on focus of the custom columnstyle), the problem was
the fact that if you hit enter it would go to the next row.
Now I would expect tab to be used for moving around, but
it appears someone at MS doesn't like tab and likes using
enter and the arrow keys to move to different Cells.

Ok So I need a way to be able to hit enter and it go to
another line in the textbox. I figured out how to do this,
I built a seperate project with a textbox and different
buttons and I'm sending messages to the wndproc of the
textbox. I got all the operations to work in my sample
probject. Though when I went to add them into my datagrid
I did the following. Note: it might not look good here.

Protected Overrides Function ProcessCmdKey(ByRef msg As
System.Windows.Forms.Message, ByVal keyData As
System.Windows.Forms.Keys) As Boolean
Dim KC As Keys = CType((msg.WParam.ToInt32 And
Keys.KeyCode), Keys)
If (msg.Msg = WM_KEYDOWN Or msg.Msg = WM_KEYUP)
Then
Dim DisableKeys As Boolean
Try
DisableKeys = CType
(Me.GetActiveTableStyle.GridColumnStyles
(Me.CurrentCell.ColumnNumber),
DataGridExt.DataGridExtensions.DataGridMultiLineTextboxColu
mnStyle).IsKeysDisabled
Catch
Return False
End Try
If DisableKeys = True Then
If KC = Keys.Enter Or KC = Keys.Up Or KC =
Keys.Down Then
Dim M As New
System.Windows.Forms.Message
M.HWnd = CType
(Me.GetActiveTableStyle.GridColumnStyles
(Me.CurrentCell.ColumnNumber),
DataGridExt.DataGridExtensions.DataGridMultiLineTextboxColu
mnStyle).Box.Handle
Select Case KC
Case Keys.Enter
M.LParam = IntPtr.Zero
M.Msg = Me.WM_CHAR
M.WParam = IntPtr.op_Explicit
(Keys.Enter)
Case Keys.Up
M.LParam = IntPtr.Zero
M.Msg = Me.WM_KEYDOWN
M.WParam = IntPtr.op_Explicit
(Me.VK_UP)
Case Keys.Down
M.LParam = IntPtr.Zero
M.Msg = Me.WM_KEYDOWN
M.WParam = IntPtr.op_Explicit
(Me.VK_DOWN)
End Select

CType
(Me.GetActiveTableStyle.GridColumnStyles
(Me.CurrentCell.ColumnNumber),
DataGridExt.DataGridExtensions.DataGridMultiLineTextboxColu
mnStyle).Box.SendMessage(M)

Return True
End If
End If
If KC = Keys.Left Or KC = Keys.Right Then
Select Case KC
Case Keys.Left
If CType
(Me.GetActiveTableStyle.GridColumnStyles
(Me.CurrentCell.ColumnNumber),
DataGridExt.DataGridExtensions.DataGridMultiLineTextboxColu
mnStyle).Box.SelectionStart > 0 Then
CType
(Me.GetActiveTableStyle.GridColumnStyles
(Me.CurrentCell.ColumnNumber),
DataGridExt.DataGridExtensions.DataGridMultiLineTextboxColu
mnStyle).Box.SelectionStart -= 1
End If
Case Keys.Right
CType
(Me.GetActiveTableStyle.GridColumnStyles
(Me.CurrentCell.ColumnNumber),
DataGridExt.DataGridExtensions.DataGridMultiLineTextboxColu
mnStyle).Box.SelectionStart += 1
End Select
Return True
End If
End If
Return False
End Function



Ok So you would think everything works huh? well the enter
works and the left and right work fine, but the up and
down do not work inside the textbox, they still cause row
changes (navagation of the rows in the datagrid). What do
you guys think I'm doing wrong?

Now from what I learned doing alot of googleing is that if
the textbox has a parent control it will route the
messages to the parent (which is why I had to do the
override here), now the enter works fine. Though I found
that arrow keys are handled differently. So basiclly I
need to find an answer to my problem which is to keep the
darn arrow keys working within the textbox only.

Waiting for those great answers.

Joe

Re: Datagrid and Arrow keys, how to make the arrow move around? by Dmitriy

Dmitriy
Fri Jan 09 10:09:39 CST 2004

Joe,

You can also try a similar approach by overriding the grid's
ProcessDialogKey and ProcessKeyPreview methods. The latter seems to be
called before a keystroke is dispatched to a hosted textbox or another
control used to edit the cell content.

--
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

"Joe" <jfuentes@classicfs.com> wrote in message
news:010c01c3d600$f2bfb560$a101280a@phx.gbl...
> Ok Simple problem.
>
> I have a MS datagrid I made my very own multiline
> columnstyle for my datagrid. Right away I had problems.
> Yea it was multiline (using a regular textbox that shows
> up on focus of the custom columnstyle), the problem was
> the fact that if you hit enter it would go to the next row.
> Now I would expect tab to be used for moving around, but
> it appears someone at MS doesn't like tab and likes using
> enter and the arrow keys to move to different Cells.
>
> Ok So I need a way to be able to hit enter and it go to
> another line in the textbox. I figured out how to do this,
> I built a seperate project with a textbox and different
> buttons and I'm sending messages to the wndproc of the
> textbox. I got all the operations to work in my sample
> probject. Though when I went to add them into my datagrid
> I did the following. Note: it might not look good here.
>
> Protected Overrides Function ProcessCmdKey(ByRef msg As
> System.Windows.Forms.Message, ByVal keyData As
> System.Windows.Forms.Keys) As Boolean
> Dim KC As Keys = CType((msg.WParam.ToInt32 And
> Keys.KeyCode), Keys)
> If (msg.Msg = WM_KEYDOWN Or msg.Msg = WM_KEYUP)
> Then
> Dim DisableKeys As Boolean
> Try
> DisableKeys = CType
> (Me.GetActiveTableStyle.GridColumnStyles
> (Me.CurrentCell.ColumnNumber),
> DataGridExt.DataGridExtensions.DataGridMultiLineTextboxColu
> mnStyle).IsKeysDisabled
> Catch
> Return False
> End Try
> If DisableKeys = True Then
> If KC = Keys.Enter Or KC = Keys.Up Or KC =
> Keys.Down Then
> Dim M As New
> System.Windows.Forms.Message
> M.HWnd = CType
> (Me.GetActiveTableStyle.GridColumnStyles
> (Me.CurrentCell.ColumnNumber),
> DataGridExt.DataGridExtensions.DataGridMultiLineTextboxColu
> mnStyle).Box.Handle
> Select Case KC
> Case Keys.Enter
> M.LParam = IntPtr.Zero
> M.Msg = Me.WM_CHAR
> M.WParam = IntPtr.op_Explicit
> (Keys.Enter)
> Case Keys.Up
> M.LParam = IntPtr.Zero
> M.Msg = Me.WM_KEYDOWN
> M.WParam = IntPtr.op_Explicit
> (Me.VK_UP)
> Case Keys.Down
> M.LParam = IntPtr.Zero
> M.Msg = Me.WM_KEYDOWN
> M.WParam = IntPtr.op_Explicit
> (Me.VK_DOWN)
> End Select
>
> CType
> (Me.GetActiveTableStyle.GridColumnStyles
> (Me.CurrentCell.ColumnNumber),
> DataGridExt.DataGridExtensions.DataGridMultiLineTextboxColu
> mnStyle).Box.SendMessage(M)
>
> Return True
> End If
> End If
> If KC = Keys.Left Or KC = Keys.Right Then
> Select Case KC
> Case Keys.Left
> If CType
> (Me.GetActiveTableStyle.GridColumnStyles
> (Me.CurrentCell.ColumnNumber),
> DataGridExt.DataGridExtensions.DataGridMultiLineTextboxColu
> mnStyle).Box.SelectionStart > 0 Then
> CType
> (Me.GetActiveTableStyle.GridColumnStyles
> (Me.CurrentCell.ColumnNumber),
> DataGridExt.DataGridExtensions.DataGridMultiLineTextboxColu
> mnStyle).Box.SelectionStart -= 1
> End If
> Case Keys.Right
> CType
> (Me.GetActiveTableStyle.GridColumnStyles
> (Me.CurrentCell.ColumnNumber),
> DataGridExt.DataGridExtensions.DataGridMultiLineTextboxColu
> mnStyle).Box.SelectionStart += 1
> End Select
> Return True
> End If
> End If
> Return False
> End Function
>
>
>
> Ok So you would think everything works huh? well the enter
> works and the left and right work fine, but the up and
> down do not work inside the textbox, they still cause row
> changes (navagation of the rows in the datagrid). What do
> you guys think I'm doing wrong?
>
> Now from what I learned doing alot of googleing is that if
> the textbox has a parent control it will route the
> messages to the parent (which is why I had to do the
> override here), now the enter works fine. Though I found
> that arrow keys are handled differently. So basiclly I
> need to find an answer to my problem which is to keep the
> darn arrow keys working within the textbox only.
>
> Waiting for those great answers.
>
> Joe