Property grid navigation

  • Thread starter John J. Hughes II
  • Start date

J

John J. Hughes II

I have implimented a custom data grid and property gid on several of my
forms. I find it really nice when updating multiple record. I select a
dozen record or so and the property grid gives me the fields to change and
the ones I change affect all.

The problem is I have several customer complaining about the property grid
navigation. I guess most people have gotten use to the tab key for field
changing.

Is there maybe some directions on property grid navigation I could refer to?
I can only assume I am doing it wrong.

Regards,
John
 
Ad

Advertisements

J

Jeffrey Tan[MSFT]

Hi John,

Based on my understanding, you want to add the Tab key navigation in
WinForm PropertyGrid control.
======================================
To get this done, we may customize a PropertyGrid intercept the Tab keydown
message and translate it into next grid cell selection operation.
We may override PropertyGrid.ProcessKeyPreview method, and determine the
Tab key down message.
To get the next grid item reference, we can first get the selecteditem's
parent grid item's reference, then loop through its child items, the next
reference after the selected item is what we need.

Code snippet lists below:
public class MyPropertygrid : System.Windows.Forms.PropertyGrid
{
const int WM_KEYDOWN=0x100;
const int VK_TAB=0x09;
protected override bool ProcessKeyPreview(ref Message m)
{
if(m.Msg==WM_KEYDOWN)
{
if(m.WParam==(IntPtr)VK_TAB)
{
GridItem gi=this.SelectedGridItem;
GridItem p_gi=gi.Parent;
int i;
for(i=0;i<p_gi.GridItems.Count;i++)
{
if(p_gi.GridItems==gi)
{
break;
}
}
p_gi.GridItems[i+1].Select();
return true;
}
}
return base.ProcessKeyPreview (ref m);
}
}

=====================================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
J

John J. Hughes II

Jeffrey,

Well sort of... what I was really looking for was direction to how the
property gird worked in the first place. I was assuming there had to be a
way of using the silly thing without the mouse due to the handicapped user
interface requirements and all.

Oh well being greedy and all :) I am more then willing to use your code
sample to get where I need to be, thank you.

I assume you don't spend a lot of time on it so just a couple notes in case
anyone else who is using it has a problem.

1) If you try to tab on the last item there is no check for 'i' being past
the end of the items array so the code crashes. I have added the following
to fix that.

if(++i < p_gi.GridItems.Count)
{
p_gi.GridItems.Select();
}

2) If there is more then one group the code with the above change will not
go past the end of the first group. The change in the below code will move
to the first item in the next group. Below is a larger sample. If the
groups are futher nested I am assuming it will again stop working but since
I don't need more then one group level I am not planing on fixing it.

protected override bool ProcessKeyPreview(ref Message m)
{
if(m.Msg==WM_KEYDOWN)
{
if(m.WParam==(IntPtr)VK_TAB)
{
GridItem gi = this.SelectedGridItem;
GridItem p_gi = gi.Parent;

int i;
for(i=0; i < p_gi.GridItems.Count; i++)
{
if(p_gi.GridItems == gi)
{
break;
}
}
if(++i < p_gi.GridItems.Count)
{
p_gi.GridItems.Select();
}
else if(p_gi.GridItemType != System.Windows.Forms.GridItemType.Root)
{
GridItem r_gi = p_gi.Parent;
for(i=0; i < r_gi.GridItems.Count; i++)
{
if(r_gi.GridItems == p_gi)
{
break;
}
}
if(++i < r_gi.GridItems.Count)
{
if(r_gi.GridItems.GridItems.Count > 0)
r_gi.GridItems.GridItems[0].Select();
else
r_gi.GridItems.Select();
}
}
return true;
}
}
return base.ProcessKeyPreview (ref m);
}

Regards,
John
 
Ad

Advertisements

J

Jeffrey Tan[MSFT]

Hi John,

Thanks for sharing the information with the community!

Yes, I just want to show you the main direction, so I did not fully test my
code, it is just a simple code snippet. :)

If you need further help, please feel free to tell me. Thanks again.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

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

Similar Threads

Property Grid 0
Property Grid 0
Property Grid 1
property grid 1
Finding Grid Positions in a Property Grid 0
Problem with property grid 0
Property grid with listview 0
multicolumn property-grid 0

Top