This is a migrated thread and some comments may be shown as answers.

Use Tab Key to select next property?

14 Answers 650 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 22 May 2012, 10:04 PM
Hi

Is it possible to set the focus to the next [index++ in current sortorder] or to a named propertyfield when pressing Tab-Key in Editing-Mode. It seems that the Preview Key only works on Labels or Fields with Readonly Attribute.
private void radPropertyGridPAZ_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
    switch (e.KeyCode)      
    {
        case Keys.Tab:
            switch (radPropertyGridPAZ.SelectedGridItem.Name) 
            {
                case "JobNo":
                    radPropertyGridPAZ.Items["TaskNo"].Select(); 
                    break;
            }
            break;
    }
}

Thanks in advance :-)
Daniel Kaelin

14 Answers, 1 is accepted

Sort by
0
Ivan Petrov
Telerik team
answered on 25 May 2012, 01:12 PM
Hi Daniel,

Thank you for writing.

To achieve the desired behavior you will have to subscribe to the PreviewKeyDown event of each editor. You can use the EditorInitialized event of RadPropertyGrid for the purpose. Here is an example for three of the editors:
private void radPropertyGrid1_EditorInitialized(object sender, PropertyGridItemEditorInitializedEventArgs e)
{
  if (e.Editor is PropertyGridSpinEditor)
  {
    PropertyGridSpinEditor editor = (PropertyGridSpinEditor)e.Editor;
    ((BaseSpinEditorElement)editor.EditorElement).TextBoxItem.HostedControl.PreviewKeyDown += new PreviewKeyDownEventHandler(HostedControl_PreviewKeyDown);
  }
  else if (e.Editor is PropertyGridTextBoxEditor)
  {
    PropertyGridTextBoxEditor edior = (PropertyGridTextBoxEditor)e.Editor;
    ((BaseTextBoxEditorElement)edior.EditorElement).TextBoxItem.HostedControl.PreviewKeyDown +=new PreviewKeyDownEventHandler(HostedControl_PreviewKeyDown);
  }
  else if (e.Editor is PropertyGridDateTimeEditor)
  {
    PropertyGridDateTimeEditor editor = (PropertyGridDateTimeEditor)e.Editor;
    ((BaseDateTimeEditorElement)editor.EditorElement).TextBoxElement.TextBoxItem.HostedControl.PreviewKeyDown +=new PreviewKeyDownEventHandler(HostedControl_PreviewKeyDown);
  }
  //...other editors
}

I hope this will be useful. If you have further questions, I would be glad to help.

All the best,
Ivan Petrov
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Daniel
Top achievements
Rank 1
answered on 17 Sep 2012, 10:07 AM
Hi,

How do I set the items to be in edit mode after the user push the tab key ?
If I use the Select() method it will only put the item into selected mode.
I have tried using BeginEdit(), it will set the item to edit mode but it will automatically set the item to end edit and set it back to selected mode.

Regards,
daniel
0
Ivan Petrov
Telerik team
answered on 20 Sep 2012, 10:34 AM
Hello Daniel,

Thank you for writing back.

Please, find attached an example project where I have implemented your scenario. When closing and opening an item for edit within the PreviewKeyDown the event is fired twice. To overcome this the property grid KeyDown event is used to unsubscribe from the event.

I hope this will help. If you have further questions, do not hesitate to write back.
 
All the best,
Ivan Petrov
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
0
Daniel
Top achievements
Rank 1
answered on 25 Sep 2012, 06:45 AM
I tried your code but modified the SomeClass properties into strings, as my codes require a string property.
You have to press tab twice to actually edit the content (cursor is inside the box and waiting key press).
After I tab once, the textbox in the property grid is indeed in edit mode, but when I tried to input using key press, no character can be inputted.

Can you tell me what's wrong with it ?

Regards,
Daniel
0
Ivan Petrov
Telerik team
answered on 27 Sep 2012, 03:29 PM
Hi Daniel,

Thank you for writing.

This behavior is caused by the fact that we use the standard TextBox control inside ours. The standard text box has a special behavior for the Tab key and if its properties Multiline and AcceptsTab are not set to true, it does not fire the KeyDown event. This is preventing us to achieve your scenario properly. To work around this, you can simply simulate the second tab press by sending a message to the application. I have modified the project in accordance to the above and your change of the type of the properties.

Should you need further assistance, feel free to contact us.

Greetings,
Ivan Petrov
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
0
Kristoffer
Top achievements
Rank 1
answered on 23 Apr 2014, 08:37 AM
I added a Button and a TextBox to Form1. Now the tabbing does not work. Suggestions?
0
Dimitar
Telerik team
answered on 23 Apr 2014, 11:55 AM
Hi Kristoffer,

Thank you for writing.

To achieve the desired behavior and to handle the tab pressing properly you can create a custom RadPropertyGrid class and override the ProcessDialogKey method. For example: 
public class MyPropertyGrid : RadPropertyGrid
{
    protected override bool ProcessDialogKey(Keys keyData)
    {
        if (keyData == Keys.Tab)
        {
            int index = this.Items.IndexOf((PropertyGridItem)this.SelectedGridItem);
 
            if (!(index < 0 || index >= this.Items.Count - 1))
            {
                this.SelectedGridItem = this.Items[++index];
                this.BeginEdit();
                return true;
            }
            else
            {
                return base.ProcessDialogKey(keyData);
            }
            
        }
        else
        {
            return base.ProcessDialogKey(keyData);
        }
 
    }
    public override string ThemeClassName
    {
        get
        {
            return typeof(RadPropertyGrid).FullName;
        }
    }
}

I hope this helps. Should you have any other questions do not hesitate to ask.
 
Regards,
Dimitar
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Kristoffer
Top achievements
Rank 1
answered on 23 Apr 2014, 01:23 PM
Thanks. Almost there! Now we just need a way to tab over (skip) group items. Ideas? :)

E.g.: "Group 1" has item "A" and "B". "Group 2" has item "C" and "D". At "B" I press TAB and expect it to start editing "C".
0
Kristoffer
Top achievements
Rank 1
answered on 23 Apr 2014, 01:34 PM
Got it working. Thanks for your help!

​
protected override bool ProcessDialogKey(Keys keyData)
{
    if (keyData == Keys.Tab || keyData == (Keys.Tab | Keys.Shift))
    {
        var gridItem = SelectedGridItem as PropertyGridItem;
        if (gridItem != null)
        {
            PropertyGridItem selectedItem = null;
 
            if (keyData == Keys.Tab)
            {
                selectedItem = Items.ElementAtOrDefault(Items.IndexOf(gridItem) + 1);
 
                if (selectedItem == null)
                {
                    var currentGroup = Groups.SingleOrDefault(g => g.Name == gridItem.Category);
                    var nextGroup = Groups.ElementAtOrDefault(Groups.IndexOf(currentGroup) + 1);
 
                    if (nextGroup != null)
                    {
                        selectedItem = nextGroup.GridItems.FirstOrDefault();
                    }
                }
            }
            else
            {
                selectedItem = Items.ElementAtOrDefault(Items.IndexOf(gridItem) - 1);
 
                if (selectedItem == null)
                {
                    var currentGroup = Groups.SingleOrDefault(g => g.Name == gridItem.Category);
                    var previousGroup = Groups.ElementAtOrDefault(Groups.IndexOf(currentGroup) - 1);
 
                    if (previousGroup != null)
                    {
                        selectedItem = previousGroup.GridItems.LastOrDefault();
                    }
                }
            }
 
            if (selectedItem != null)
            {
                SelectedGridItem = selectedItem;
                BeginEdit();
 
                return true;
            }
        }
    }
     
    return base.ProcessDialogKey(keyData);
}
0
Dimitar
Telerik team
answered on 24 Apr 2014, 08:48 AM
Hello Kristoffer,

I am glad that you have sorted this out and thank you for sharing your solution with the community. I am sure someone will benefit from it.

Do not hesitate to contact us if you have other questions.
 
Regards,
Dimitar
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Moe
Top achievements
Rank 1
answered on 11 Sep 2014, 02:47 AM
So based on the above solution, I am able to tab to the next control. The issue I am having, tab is jumping from control to another because I have Sorting and Grouping on. The question I have is how can I get the 'items' property after applying sorting and grouping? so when tab is clicked the next item in the propertygrid is selected sequentially .
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 15 Sep 2014, 10:45 AM
Hello Mohamed,

Thank you for writing.

You can iterate through the sorted/categorized properties items by pressing Tab key. For this purpose you should use a PropertyGridTraverser which traverses the items in a sorted/categorized order. Here is a sample code snippet:
public class MyPropertyGrid : RadPropertyGrid
{
    protected override bool ProcessDialogKey(Keys keyData)
    {
        if (keyData == Keys.Tab)
        {
            if (this.SelectedGridItem != null)
            {
                PropertyGridTraverser traverser = new PropertyGridTraverser(this.PropertyGridElement.PropertyTableElement);
  
                while (traverser.MoveNext() && traverser.Current != this.SelectedGridItem)
                {
                }
  
                traverser.MoveNext();
  
                this.SelectedGridItem = traverser.Current;
                this.BeginEdit();
  
                return true;
            }
            else
            {
                return base.ProcessDialogKey(keyData);
            }
        }
        else
        {
            return base.ProcessDialogKey(keyData);
        }
    }
  
    public override string ThemeClassName
    {
        get
        {
            return typeof(RadPropertyGrid).FullName;
        }
    }
}

I hope this information helps. Should you have further questions, I would be glad to help.

Regards,
Desislava
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Stevens
Top achievements
Rank 1
answered on 22 Jun 2018, 12:08 PM

I am using this code for moving from item to item, but when the user hovers over a toolbar button the tooltip text does not pop up.

I have another form with propertygrid  that does not have this class and the popup tooltip text shows.

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 25 Jun 2018, 10:18 AM
Hello, Stevens,   

By default, the tool tips for the toolbar buttons in RadPropertyGrid are not shown. It is necessary to handle the ToolTipTextNeeded event and specify what tool tip to be show for the toggle buttons. Here is a sample code snippet:
private void radPropertyGrid1_ToolTipTextNeeded(object sender, Telerik.WinControls.ToolTipTextNeededEventArgs e)
{
    RadToggleButtonElement toggleButton = sender as RadToggleButtonElement;
    if (toggleButton != null)
    {
        e.ToolTipText=toggleButton.GetType().ToString();
    }
}

I have also attached a sample project for your reference. 

I hope this information helps. If you have any additional questions, please let me know. 

Regards,
Dess
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
PropertyGrid
Asked by
Daniel
Top achievements
Rank 1
Answers by
Ivan Petrov
Telerik team
Daniel
Top achievements
Rank 1
Kristoffer
Top achievements
Rank 1
Dimitar
Telerik team
Moe
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Stevens
Top achievements
Rank 1
Share this question
or