HighTechTalks DotNet Forums  

Custom ComboBox DataGridColumn: on Tab combo gains then loses focu

Dotnet Framework (WinForms) microsoft.public.dotnet.framework.windowsforms


Discuss Custom ComboBox DataGridColumn: on Tab combo gains then loses focu in the Dotnet Framework (WinForms) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
jlavallet
 
Posts: n/a

Default Custom ComboBox DataGridColumn: on Tab combo gains then loses focu - 07-01-2005 , 08:46 AM






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);
}

Reply With Quote
  #2  
Old   
Dave
 
Posts: n/a

Default RE: Custom ComboBox DataGridColumn: on Tab combo gains then loses focu - 08-30-2005 , 11:37 AM






Just stumbled on this one myself.
Did you ever find a solution?

Thanks,
Dave

"jlavallet" wrote:

Quote:
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);
}

Reply With Quote
  #3  
Old   
jlavallet
 
Posts: n/a

Default RE: Custom ComboBox DataGridColumn: on Tab combo gains then loses - 09-01-2005 , 08:33 AM



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:

Quote:
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);
}

Reply With Quote
  #4  
Old   
Dave
 
Posts: n/a

Default RE: Custom ComboBox DataGridColumn: on Tab combo gains then loses - 09-01-2005 , 02:56 PM



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:

Quote:
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);
}

Reply With Quote
  #5  
Old   
jlavallet
 
Posts: n/a

Default RE: Custom ComboBox DataGridColumn: on Tab combo gains then loses - 09-01-2005 , 05:05 PM



Thanks Dave, I'll check it out.

"Dave" wrote:

Quote:
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);
}

Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.