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

RadListBox

3 Answers 34 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Victoria F
Top achievements
Rank 1
Victoria F asked on 24 Nov 2010, 07:42 PM
C#.
I have 2  RadListBoxes.( Assign/Unassign process) 
When I Assign items (add items to the right listbox and remove them from the left listbox).
If Assign ListBox has at least 1 item I have to enable contextMenu or radcontextMenu  for this ListBox. 
So when there is at least one item user can right click and open a response window to be able to edit some details. 

My problem is that I can not assign dynamically contextMenu.
At the end of the code to assign the item I wrote:
if (radListBox_SelectLOBs.Items.Count > 0)
{
  radListBox_SelectITMs.ContextMenuStrip = contextMenuStrip_VF; 
}
but nothing happened on the right click.
Menu appears only if I specify in the property of RadListBox (RadContextMenu) at the beginning,and not using the code.
Is there an option to do this from the code?
Thank you,
Victoria.

3 Answers, 1 is accepted

Sort by
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 24 Nov 2010, 09:14 PM

Evening Victoria,

How about this...

Declare a context menu in the class

private ContextMenu m_MyMenu = new ContextMenu();

Add the menu to the RadListBox and register for the PopUp event
public Form1()
{
    InitializeComponent();
    this.radListControl1.ContextMenu = m_MyMenu;
    m_MyMenu.Popup += new System.EventHandler(this.PopUp);
}

When the popup fires, add the menu item in if there are more than 1 items
private void PopUp(object sender, EventArgs e)
{
    if (this.radListControl1.Items.Count > 0)
    {
        m_MyMenu.MenuItems.Clear();
        MenuItem meniItem = new MenuItem("Click Me");
        meniItem.Click += new System.EventHandler(this.MenuItemClicked);
        m_MyMenu.MenuItems.Add(meniItem);
        this.radListControl1.ContextMenu = m_MyMenu;
    }
}

and capture the click event of the context menu item
private void MenuItemClicked(object sender, EventArgs e)
{
    MessageBox.Show("You clicked the ClickMe context menu item");
}

Hope this helps, but let me know if you have further questions.

regards,
Richard
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 24 Nov 2010, 09:16 PM
Slightly revised. One line not needed
private void PopUp(object sender, EventArgs e)
{
    if (this.radListControl1.Items.Count > 0)
    {
        m_MyMenu.MenuItems.Clear();
        MenuItem meniItem = new MenuItem("Click Me");
        meniItem.Click += new System.EventHandler(this.MenuItemClicked);
        m_MyMenu.MenuItems.Add(meniItem);
        //this.radListControl1.ContextMenu = m_MyMenu;
    }
}
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 25 Nov 2010, 10:33 AM
Hello Victoria, Richard,

If this problem has been solved please mark this question as answered, and i would like to ask you if possible to please create the threads in their corresponding sections, this way it will be easier for other users to find the answers to their questions faster.

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
Telerik WinForms MVP
Tags
GridView
Asked by
Victoria F
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Emanuel Varga
Top achievements
Rank 1
Share this question
or