public class CustomDataGrid : System.Windows.Forms.DataGri
protected override bool ProcessCmdKey(ref Message msg, Keys keyData
if ((keyData & Keys.Tab) > 0
this.TopLevelControl.SelectNextControl(this, (!((keyData & Keys.Shift
return true
return base.ProcessCmdKey(ref msg, keyData)
My replies don't seem to be going through so I'm posting through another server. Sorry for the delay. Tim's code from above is similar to the method I was going to suggest. I'm assuming you have mixed columns (read only sometimes). I would suggest using a send key for the tabs instead of the selectnextcontrol because I don't believe that will invoke the ProcessCmdKey method on the next column and if the next column is readonly then you still have a problem. This adds some work to the situation though since you have to determine which direction you are going (SHIFT+TAB or TAB). Also, neither of these solutions provide any help if the user simply clicks on the cell. Below is some code I used to select the entire row of a datagrid when a user clicks on a cell and the datasource is a dataview. There is some additional logic in it that allows/disallows editing/deleting based upon the current state of the dataview but that's not as important. I believe you could modify this to do what you are looking to do
<code
public class ControlledDeleteDataGrid : System.Windows.Forms.DataGrid
private int currentRow = -1
protected override bool ProcessKeyPreview( ref Message msg )
{
// unselect the currently selected row/cell/..
if(currentRow > -1 && currentRow < this.ListManager.List.Count + 1)
this.UnSelect(currentRow);
// select the row from abov
this.Select( (currentRow=this.CurrentRowIndex) )
Keys keyCode = (Keys)(int)msg.WParam & Keys.KeyCode;
// if the keydown was delete and deletes are allowe
if(msg.Msg == WM_KEYDOWN
&& keyCode == Keys.Delete
&& this.DataSource is DataVie
&& ((DataView) this.DataSource).AllowDelete)
{
if(MessageBox.Show("Are you sure you want this row deleted?", "Confirm Delete", MessageBoxButtons.YesNo) == DialogResult.No)
return true
}
// if the keydown was anything else and edits are allowe
else if (msg.Msg == WM_KEYDOWN
&& this.DataSource is DataVie
&& ((DataView) this.DataSource).AllowEdit)
return true
// if none of the other conditions are met pass message on to base pre processin
return base.PreProcessMessage(ref msg);
}
// win32 message id const
private const int WM_KEYDOWN = 0x100
private const int WM_KEYUP = 0x101
</code>