PC Review


Reply
Thread Tools Rate Thread

Movement to rows in a DataGrid

 
 
Faith
Guest
Posts: n/a
 
      2nd Oct 2003
Hi there.
I need the TAB key to work like the ENTER key in a Data
Grid. Basically I have several columns in a Data Grid and
only the first column is editable (or not Read Only).
When the user types in a number (in column 0) and presses
the TAB key it goes into the Read Only (non-editable)
column (column 1), I need it to go to the next Row and
stay in the first column (column 0). Can someone tell me
how to do this and if it's possible? Or is there any
reference web site out there you can point me to?

Thanks so much!
Faith
 
Reply With Quote
 
 
 
 
Tian Min Huang
Guest
Posts: n/a
 
      3rd Oct 2003
Hi Faith,

Thanks for your post. We can intercept TAB key in DataGrid control, and
then set the focus to corresponding Cell. Here is the detailed steps:

1. We must create a DataGrid-derived class in order to trap keytrokes in
the DataGrid. Please refer to the following code snippet:

//------------------code snippet------------------
public class MyDataGrid: DataGrid
{
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
const int WM_KEYDOWN = 0x100;
const int WM_SYSKEYDOWN = 0x104;

if ((msg.Msg == WM_KEYDOWN) || (msg.Msg == WM_SYSKEYDOWN))
{
switch(keyData)
{
case Keys.Tab:
this.CurrentCell = new
DataGridCell(this.CurrentCell.RowNumber+1,0);
return true;
}
}
return base.ProcessCmdKey(ref msg,keyData);
}
}
//------------------end of-------------------

2. In the Form class, declare and create the DataGrid as MyDataGrid.

CHANGE:
private System.Windows.Forms.DataGrid dataGrid1;
this.dataGrid1 = new System.Windows.Forms.DataGrid();

TO:
private MyDataGrid dataGrid1;
this.dataGrid1 = new MyDataGrid();

Please refer to the following KB article for detailed information:
HOW TO: Trap Keystrokes in .NET Controls by Using Visual C# .NET
http://support.microsoft.com/?id=320584

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

 
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
DataGrid, Windows - Does not refresh. data is in the rows but they are not visible, the rows are solid blue Richard Microsoft C# .NET 1 2nd Sep 2005 02:56 PM
Rows 12 thru 24 are selected in a datagrid. How do I tell when the user selects rows 45 thru 70 ??? BBFrost Microsoft C# .NET 6 26th Oct 2004 05:37 AM
datagrid scrolling...capturihng rows displayed in view of datagrid Patrick Microsoft Dot NET Framework Forms 3 7th Jun 2004 12:07 PM
searching a datagrid's rows and displaying rows where item was found Angel Microsoft C# .NET 0 26th Apr 2004 06:51 PM
DataGrid Component | Displaying columns of a DataSet as Rows in a DataGrid ? Diego TERCERO Microsoft C# .NET 3 19th Dec 2003 03:21 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:42 PM.