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

Context menu on RadAutoCompleteBox items

2 Answers 92 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
Aleksander
Top achievements
Rank 1
Aleksander asked on 12 Aug 2016, 03:10 PM

Hi!

I'm trying to add a context menu for the RadTokenizedTextItem items in the RadAutoCompleteBox.Items collection. Something like the mockup-image i attached to this post.

The RadAutoCompleteBox itself has both a ContextMenu and a RadContextMenu property, but the RadTokenizedTextItem have none of these.To be clear: I want to be able to right-click an individual token in the RadAutoCompleteBox, click an option in the menu, and then catch some kind of event that includes information about that token in the eventargs. Is this even possible? If so, how would I go about doing this?

I'm using UI for WinForms.

 

Thanks,

Aleksander

2 Answers, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 15 Aug 2016, 01:00 PM
Hello Aleksander,

Thank you for writing. 

In order to customize the context menu, you can handle the ContextMenuOpening event. It is necessary to create a custom AutoCompleteBoxInputHandler in order to identify the clicked tokenized element. Here is a sample code snippet:
public Form1()
{
    InitializeComponent();
 
    this.radAutoCompleteBox1.ContextMenuOpening += radAutoCompleteBox1_ContextMenuOpening;
    this.radAutoCompleteBox1.TextBoxElement.InputHandler =
        new CustomAutoCompleteBoxInputHandler(this.radAutoCompleteBox1.TextBoxElement as RadAutoCompleteBoxElement);
}
 
private void radAutoCompleteBox1_ContextMenuOpening(object sender, TreeBoxContextMenuOpeningEventArgs e)
{
    TokenizedTextBlockElement token = this.radAutoCompleteBox1.TextBoxElement.Tag as TokenizedTextBlockElement;
    if (token != null)
    {
        //modify the context menu according to the clicked token
    }
}
 
public class CustomAutoCompleteBoxInputHandler : AutoCompleteBoxInputHandler
{
    public CustomAutoCompleteBoxInputHandler(RadAutoCompleteBoxElement textBoxElement) : base(textBoxElement)
    {
    }
 
    protected override bool ProcessContextMenu(Point location)
    {
        TokenizedTextBlockElement token = this.TextBox.ElementTree.GetElementAtPoint(location) as TokenizedTextBlockElement;
        this.TextBox.Tag = token;
        return base.ProcessContextMenu(location);
    }
}

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

Regards,
Dess
Telerik by Progress
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
0
Aleksander
Top achievements
Rank 1
answered on 16 Aug 2016, 06:40 AM
Thanks Dess, this solution works perfectly!
Tags
AutoCompleteBox
Asked by
Aleksander
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Aleksander
Top achievements
Rank 1
Share this question
or