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.
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
}