DataGrid key press question

J

James

1. up/down arrow keys to move up/down one recored at a time
2. Page Up/Down keys to move up/down one page at a time
3. CTRL+End and CTRL+Home keys to move to end and beginning(last
record and first record) of the datagrid respectively

code for page down:


public class Myform : System.Windows.Forms.Form, IMessageFilter
{
const int WM_KEYDOWN = 0x100;
const int WM_KEYUP = 0x101;


[DllImport("User32.dll")]
private static extern int SendMessage(IntPtr hWnd, int msg , int
wParam, int lParam);


public const int SBS_HORZ = 0;
public const int SBS_VERT = 1;
public const int SBS_CTL = 2;
public const int SBS_BOTH = 3;

public const int WM_VSCROLL = 0x115;
public const int WM_HSCROLL = 0x114;

public const int SB_LINEUP = 0;
public const int SB_LINEDOWN = 1;
public const int SB_PAGEUP = 2;
public const int SB_PAGEDOWN = 3;
public const int SB_THUMBPOSITION = 4;
public const int SB_THUMBTRACK = 5;
public const int SB_TOP = 6;
public const int SB_BOTTOM = 7;
public const int SB_ENDSCROLL = 8;


public bool PreFilterMessage(ref Message m)
{

Keys keyCode = (Keys)(int)m.WParam & Keys.KeyCode;

if(m.Msg == WM_KEYDOWN && keyCode == Keys.PageDown)
{
int position = 500;

SendMessage(dataGrid1.Handle, WM_VSCROLL, SB_THUMBPOSITION +
0x10000 * position,0);

return true;
}
}
}

Nothing is happening, does any one have any sample code to handle the
above mentioned events(1,2,3).

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top