Anderson Oliveira
Anderson Oliveira

Reputation: 57

How to access the event when a list of radio button is selected at a context menu strip?

I'm creating the radio buttons in the ContextMenuStrip using the ToolStripControlHost, this way

RadioButton taskRb = new RadioButton();
taskRb.Text = DataGridTable.getTasks()[i].name.ToString();
taskRb.Checked = false;
ToolStripControlHost tRb = new ToolStripControlHost(taskRb);
contextMenuStrip2.Items.Add(tRb);

I need an event like CheckedChanged for the radio buttons in this list, so I can perform some actions when one of the buttons is checked.

What is the best way to do this? since I can't use this event with the ToolStripControlHost.

Upvotes: 0

Views: 346

Answers (1)

Arian Motamedi
Arian Motamedi

Reputation: 7423

You can register an event handler for the CheckedChanged event of the RadioButton:

RadioButton taskRb = new RadioButton();

taskRb.CheckedChanged += new EventHandler(taskRb_CheckedChanged);
taskRb.Text = DataGridTable.getTasks()[i].name.ToString();
taskRb.Checked = false;

ToolStripControlHost tRb = new ToolStripControlHost(taskRb);
contextMenuStrip2.Items.Add(tRb);

protected void taskRb_CheckedChanged(object sender, EventArgs e)
{
    // Do stuff
}

Upvotes: 0

Related Questions