Custom ComboBox DataGridColumn: on Tab combo gains then loses focu

G

Guest

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.HaveComboBoxProcessKey(keyCode);
if (boolHandled) return true;
}
}
return base.ProcessCmdKey(ref msg, keyData);
}
 

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