![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hello, I have a custom DataGridColumn that displays an editable ComboBox instead of a TextBox when the control is edited. Everything id working great except for one thing: when the focus is in the column to the left of my custom column and the Tab key is pressed, my control gains focus momentarily (think milliseconds) then loses focus and the column to the right of my custom column receives the focus. What is strange is that if the Right Arrow key is pressed instead of Tab my control receives the focus and keeps it. What is even stranger is that I overrode ProcessCmdKey in my custom DataGrid to send a Right Arrow key press instead of a Tab when the Tab key is pressed and the behavior is the same as the Tab key press (I have proven that this gets called BTW). And even stranger than that in my ProcessCmdKey override I also send the Right Arrow key in place of the Enter key and this works fine! So... to recap, Right Arrow - control gains focus and keeps it. Tab (even substituted Tab) control - control gains focus breifly then loses it to the next column. Any ideas? Thanks, Jack PS - Here is my overriden ProcessCmdKey method from the custom DataGrid containing my column: protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData) { Keys keyCode = (Keys)(int) msg.WParam & Keys.KeyCode; if (msg.Msg == WM_KEYDOWN && keyCode == Keys.Delete && this.IsSelected(this.CurrentRowIndex)) { DialogResult result = MessageBox.Show( this, "Delete the selected check(s)?", "Delete Checks?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if(result == DialogResult.Yes) { DeleteSelectedChecks(); } return true; } else if (keyCode == Keys.Enter) { if (Options.Instance.CheckListOnEnterMoveToNextField) { SendKeys.Send("{RIGHT}"); return true; } else if (this.BindingContext != null && this.DataSource != null) { bool boolForceToNextRow = true; bool boolHandled = AdvanceToNextField(boolForceToNextRow); if (boolHandled) return true; } } else if (keyCode == Keys.Tab) { Console.Out.WriteLine("tab - sending right"); SendKeys.Send("{RIGHT}"); return true; } else if (keyCode == Keys.Right) { Console.Out.WriteLine("right"); if (this.BindingContext != null && this.DataSource != null) { bool boolForceToNextRow = false; bool boolHandled = AdvanceToNextField(boolForceToNextRow); Console.Out.WriteLine("handled"); if (boolHandled) return true; } } else if (keyCode == Keys.Up || keyCode == Keys.Down) { if (this.CurrentCell.ColumnNumber == 2) { bool boolHandled = dataGridTextBoxColumnPayorName.HaveComboBoxProcess Key(keyCode); if (boolHandled) return true; } } return base.ProcessCmdKey(ref msg, keyData); } |
#3
| |||
| |||
|
|
Just stumbled on this one myself. Did you ever find a solution? Thanks, Dave "jlavallet" wrote: Hello, I have a custom DataGridColumn that displays an editable ComboBox instead of a TextBox when the control is edited. Everything id working great except for one thing: when the focus is in the column to the left of my custom column and the Tab key is pressed, my control gains focus momentarily (think milliseconds) then loses focus and the column to the right of my custom column receives the focus. What is strange is that if the Right Arrow key is pressed instead of Tab my control receives the focus and keeps it. What is even stranger is that I overrode ProcessCmdKey in my custom DataGrid to send a Right Arrow key press instead of a Tab when the Tab key is pressed and the behavior is the same as the Tab key press (I have proven that this gets called BTW). And even stranger than that in my ProcessCmdKey override I also send the Right Arrow key in place of the Enter key and this works fine! So... to recap, Right Arrow - control gains focus and keeps it. Tab (even substituted Tab) control - control gains focus breifly then loses it to the next column. Any ideas? Thanks, Jack PS - Here is my overriden ProcessCmdKey method from the custom DataGrid containing my column: protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData) { Keys keyCode = (Keys)(int) msg.WParam & Keys.KeyCode; if (msg.Msg == WM_KEYDOWN && keyCode == Keys.Delete && this.IsSelected(this.CurrentRowIndex)) { DialogResult result = MessageBox.Show( this, "Delete the selected check(s)?", "Delete Checks?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if(result == DialogResult.Yes) { DeleteSelectedChecks(); } return true; } else if (keyCode == Keys.Enter) { if (Options.Instance.CheckListOnEnterMoveToNextField) { SendKeys.Send("{RIGHT}"); return true; } else if (this.BindingContext != null && this.DataSource != null) { bool boolForceToNextRow = true; bool boolHandled = AdvanceToNextField(boolForceToNextRow); if (boolHandled) return true; } } else if (keyCode == Keys.Tab) { Console.Out.WriteLine("tab - sending right"); SendKeys.Send("{RIGHT}"); return true; } else if (keyCode == Keys.Right) { Console.Out.WriteLine("right"); if (this.BindingContext != null && this.DataSource != null) { bool boolForceToNextRow = false; bool boolHandled = AdvanceToNextField(boolForceToNextRow); Console.Out.WriteLine("handled"); if (boolHandled) return true; } } else if (keyCode == Keys.Up || keyCode == Keys.Down) { if (this.CurrentCell.ColumnNumber == 2) { bool boolHandled = dataGridTextBoxColumnPayorName.HaveComboBoxProcess Key(keyCode); if (boolHandled) return true; } } return base.ProcessCmdKey(ref msg, keyData); } |
#4
| |||
| |||
|
|
Not yet but then I've been distracted by another project since I wrote this message. I'll be looking at it next week and if I discover a reason/solution I'll let you know. Will you do the same? Thanks, Jack "Dave" wrote: Just stumbled on this one myself. Did you ever find a solution? Thanks, Dave "jlavallet" wrote: Hello, I have a custom DataGridColumn that displays an editable ComboBox instead of a TextBox when the control is edited. Everything id working great except for one thing: when the focus is in the column to the left of my custom column and the Tab key is pressed, my control gains focus momentarily (think milliseconds) then loses focus and the column to the right of my custom column receives the focus. What is strange is that if the Right Arrow key is pressed instead of Tab my control receives the focus and keeps it. What is even stranger is that I overrode ProcessCmdKey in my custom DataGrid to send a Right Arrow key press instead of a Tab when the Tab key is pressed and the behavior is the same as the Tab key press (I have proven that this gets called BTW). And even stranger than that in my ProcessCmdKey override I also send the Right Arrow key in place of the Enter key and this works fine! So... to recap, Right Arrow - control gains focus and keeps it. Tab (even substituted Tab) control - control gains focus breifly then loses it to the next column. Any ideas? Thanks, Jack PS - Here is my overriden ProcessCmdKey method from the custom DataGrid containing my column: protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData) { Keys keyCode = (Keys)(int) msg.WParam & Keys.KeyCode; if (msg.Msg == WM_KEYDOWN && keyCode == Keys.Delete && this.IsSelected(this.CurrentRowIndex)) { DialogResult result = MessageBox.Show( this, "Delete the selected check(s)?", "Delete Checks?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if(result == DialogResult.Yes) { DeleteSelectedChecks(); } return true; } else if (keyCode == Keys.Enter) { if (Options.Instance.CheckListOnEnterMoveToNextField) { SendKeys.Send("{RIGHT}"); return true; } else if (this.BindingContext != null && this.DataSource != null) { bool boolForceToNextRow = true; bool boolHandled = AdvanceToNextField(boolForceToNextRow); if (boolHandled) return true; } } else if (keyCode == Keys.Tab) { Console.Out.WriteLine("tab - sending right"); SendKeys.Send("{RIGHT}"); return true; } else if (keyCode == Keys.Right) { Console.Out.WriteLine("right"); if (this.BindingContext != null && this.DataSource != null) { bool boolForceToNextRow = false; bool boolHandled = AdvanceToNextField(boolForceToNextRow); Console.Out.WriteLine("handled"); if (boolHandled) return true; } } else if (keyCode == Keys.Up || keyCode == Keys.Down) { if (this.CurrentCell.ColumnNumber == 2) { bool boolHandled = dataGridTextBoxColumnPayorName.HaveComboBoxProcess Key(keyCode); if (boolHandled) return true; } } return base.ProcessCmdKey(ref msg, keyData); } |
#5
| |||
| |||
|
|
You have to override: protected override void WndProc(ref System.Windows.Forms.Message theMessage) Take a look at this article: http://www.akadia.com/services/dotnet_combobox_in_datagrid.html Cheers, Dave "jlavallet" wrote: Not yet but then I've been distracted by another project since I wrote this message. I'll be looking at it next week and if I discover a reason/solution I'll let you know. Will you do the same? Thanks, Jack "Dave" wrote: Just stumbled on this one myself. Did you ever find a solution? Thanks, Dave "jlavallet" wrote: Hello, I have a custom DataGridColumn that displays an editable ComboBox instead of a TextBox when the control is edited. Everything id working great except for one thing: when the focus is in the column to the left of my custom column and the Tab key is pressed, my control gains focus momentarily (think milliseconds) then loses focus and the column to the right of my custom column receives the focus. What is strange is that if the Right Arrow key is pressed instead of Tab my control receives the focus and keeps it. What is even stranger is that I overrode ProcessCmdKey in my custom DataGrid to send a Right Arrow key press instead of a Tab when the Tab key is pressed and the behavior is the same as the Tab key press (I have proven that this gets called BTW). And even stranger than that in my ProcessCmdKey override I also send the Right Arrow key in place of the Enter key and this works fine! So... to recap, Right Arrow - control gains focus and keeps it. Tab (even substituted Tab) control - control gains focus breifly then loses it to the next column. Any ideas? Thanks, Jack PS - Here is my overriden ProcessCmdKey method from the custom DataGrid containing my column: protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData) { Keys keyCode = (Keys)(int) msg.WParam & Keys.KeyCode; if (msg.Msg == WM_KEYDOWN && keyCode == Keys.Delete && this.IsSelected(this.CurrentRowIndex)) { DialogResult result = MessageBox.Show( this, "Delete the selected check(s)?", "Delete Checks?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if(result == DialogResult.Yes) { DeleteSelectedChecks(); } return true; } else if (keyCode == Keys.Enter) { if (Options.Instance.CheckListOnEnterMoveToNextField) { SendKeys.Send("{RIGHT}"); return true; } else if (this.BindingContext != null && this.DataSource != null) { bool boolForceToNextRow = true; bool boolHandled = AdvanceToNextField(boolForceToNextRow); if (boolHandled) return true; } } else if (keyCode == Keys.Tab) { Console.Out.WriteLine("tab - sending right"); SendKeys.Send("{RIGHT}"); return true; } else if (keyCode == Keys.Right) { Console.Out.WriteLine("right"); if (this.BindingContext != null && this.DataSource != null) { bool boolForceToNextRow = false; bool boolHandled = AdvanceToNextField(boolForceToNextRow); Console.Out.WriteLine("handled"); if (boolHandled) return true; } } else if (keyCode == Keys.Up || keyCode == Keys.Down) { if (this.CurrentCell.ColumnNumber == 2) { bool boolHandled = dataGridTextBoxColumnPayorName.HaveComboBoxProcess Key(keyCode); if (boolHandled) return true; } } return base.ProcessCmdKey(ref msg, keyData); } |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |