472,101 Members | 1,478 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,101 software developers and data experts.

PropertyGrid - Select Value Cell from code

This is a silly question, but now I have spent hours trying to figure it out. Thus, asking this forum:

Our application GUI has a .NET PropertyGrid. Our customers don't find it intuitive to navigate it using the keyboard (and I agree).

The default behaviour of the PropertyGrid (PG) is that when a row is selected, the property name is highlighted, but the value column/cell is not. Still, it is perfectly OK to enter values into the "value cell" using the keyboard. This is not intuitive to our customers, neither to me.

BUT, if the PG has focus, a grid row is selected, and you press <TAB>: the value cell gets highlighted and gets focus for editing.

How can you acheive this programatically? I have tried to inherit from the PG class and override various methods/event, without succsess.

Best regards, Henrik
Jan 28 '08 #1
2 2647
7,872 Expert 4TB
I had to look this object up, had never heard of it.
This is the same as the Properties window in Visual Studio, in functionality too.
Was kinda neat to change the properties of my window at runtime like that.

I'm not sure what's not intuitive. It's not intuitive that if you select a row, that you can type and the value will change, then they will do it the "long way" by selecting the value and editing it?

The alternative would be to use another control?
Jan 28 '08 #2
I found out how to do it, in case anybody is intrested.

In a class that inherits PropertyGrid do:
Expand|Select|Wrap|Line Numbers
  1.         protected override void OnSelectedGridItemChanged(SelectedGridItemChangedEventArgs e)
  2.         {
  3.             foreach (Control control in base.ActiveControl.Controls)
  4.             {
  5.                 if (control.GetType().ToString() ==
  6.                     "System.Windows.Forms.PropertyGridInternal." +
  7.                     "PropertyGridView+GridViewEdit")
  8.                 {
  9.                     if (control is TextBox)
  10.                     {
  11.                         (control as TextBox).Focus();
  12.                         (control as TextBox).SelectAll();
  13.                     }
  14.                 }
  15.             }
  16.             base.OnSelectedGridItemChanged(e);
  17.         }
Feb 11 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Jay Shakankar via .NET 247 | last post: by
reply views Thread by jays | last post: by
3 posts views Thread by Frank Rizzo | last post: by
1 post views Thread by ANDRES BECERRA | last post: by
3 posts views Thread by Redivivus | last post: by
8 posts views Thread by colin | last post: by
2 posts views Thread by John Hewitt | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.