PC Review


Reply
Thread Tools Rate Thread

Datagrid and Arrow keys, how to make the arrow move around?

 
 
Joe
Guest
Posts: n/a
 
      8th Jan 2004
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
 
Reply With Quote
 
 
 
 
Dmitriy Lapshin [C# / .NET MVP]
Guest
Posts: n/a
 
      9th Jan 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" <(E-Mail Removed)> wrote in message
news:010c01c3d600$f2bfb560$(E-Mail Removed)...
> 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


 
Reply With Quote
 
Joe Fuentes
Guest
Posts: n/a
 
      9th Jan 2004
Tried that, it didn't have any affect. In keypreview it wouldn't do
anything with the up or down and the enter made 3 to 4 lines instead of
one. and the other one did nothing.

I remember tyring those before and others. I read somewhere that
controls always refer back to thier parents on the arrow keys. So that
would explain why when I send it an up arrow it's going back to the grid
again. I need to stop the bouncing.

Joe



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
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
How do I get my arrow keys to allow me to move to the next cell? bbeauty19 Microsoft Excel Misc 0 13th Feb 2009 03:45 PM
Arrow keys to move cell =?Utf-8?B?UmljaGFyZA==?= Microsoft Excel Misc 2 1st May 2006 10:22 AM
arrow keys in datagrid =?Utf-8?B?b3NjYXI=?= Microsoft Dot NET Framework Forms 0 4th Jan 2005 05:35 PM
How can I move around exe worksheet with arrow keys instead of mou =?Utf-8?B?R2FpbCBFaXNlbmVja2Vy?= Microsoft Access 1 20th Oct 2004 05:20 PM
Controls do not move with arrow keys Min Microsoft Access 2 9th Oct 2004 04:36 PM


Features
 

Advertising
 

Newsgroups
 


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