RE: DataGrid Shift-Space problem -- official workaround?
- From: jetan@xxxxxxxxxxxxxxxxxxxx ("Jeffrey Tan[MSFT]")
- Date: Tue, 28 Nov 2006 03:35:08 GMT
Hi Jeff,
Yes, Shift+Space is identified as DataGrid navigation key-combination. More
specificly, it is processed in DataGrid.ProcessGridKey method. Below is the
code snippet that processes this key-combination(I got it from Reflector):
case Keys.Space:
this.gridState[0x80000] = false;
if (this.DataGridRowsLength == 0)
{
return true;
}
if (args1.Shift)
{
this.ResetSelection();
this.EndEdit();
this.DataGridRows[this.currentRow].Selected = true;
this.numSelectedRows = 1;
return true;
}
return false;
If you want to customize the DataGrid behavior to disable this default
behavior, you need modify the key-combination during the processing code
path before DataGrid.ProcessGridKey method. Based on my research, I find
that there are 2 code paths to the DataGrid.ProcessGridKey method, one from
DataGrid.ProcessDialogKey and the other from DataGrid.ProcessKeyPreview
method. So you should modify these 2 code paths by removing Shift key
effect.
Below is the sample code snippet that demonstrates the logic:
private MyDataGrid dataGrid1;
this.dataGrid1 = new MyDataGrid();
public class MyDataGrid:DataGrid
{
protected override bool ProcessDialogKey(Keys keyData)
{
if((keyData&Keys.Space)!=0)
{
return base.ProcessDialogKey(Keys.Space);
}
return base.ProcessDialogKey (keyData);
}
protected override bool ProcessKeyPreview(ref Message m)
{
KeyEventArgs args1 = new KeyEventArgs(((Keys) ((int) m.WParam)) |
Control.ModifierKeys);
if((args1.KeyCode&Keys.Space)!=0)
{
KeyEventArgs args2=new KeyEventArgs(Keys.Space);
return this.ProcessGridKey(args2);
}
return base.ProcessKeyPreview (ref m);
}
}
private void Form1_Load(object sender, System.EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("column1", typeof(int));
dt.Columns.Add("column2", typeof(string));
for (int i = 0; i < 5; i++)
{
DataRow dr = dt.NewRow();
dr["column1"] = i;
dr["column2"] = "item"+i.ToString ();
dt.Rows.Add(dr);
}
this.dataGrid1.DataSource = dt;
}
This sample project works well on my side, hope it helps.
Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
.
- Prev by Date: RE: DataGrid Sort Event
- Next by Date: RE: ListView Behaviour In Vista RTM
- Previous by thread: RE: DataGrid Sort Event
- Next by thread: embedding office 2007
- Index(es):
Relevant Pages
|