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
 
S

Shakir Hussain

James,

You must add the message filter to the application class in the form load
event

//add message filter.
Application.AddMessageFilter(this); //this= the form where IMessageFilter
is implemented

Shak
(Houston)
 
J

James

Yes I have already done that,(I did not include those parts of code).

The problem is when I want to scroll the data grid on that form. Other
functions work fine.

foe example,

if(m.Msg == WM_KEYDOWN && keyCode == Keys.F1)
{
dv.Sort = "by some column";

return true;
}

these work fine, it only does not work for scroll.

I just wanted to find out if there was anything wrong with

int position = 500;

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


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

Top