I have been stuck on this problem for awhile now, and I was hoping for some direction or an answer. How do you change the text of a ToolStripDropDownButton based off of a selected item within itself?
I have a grid that is to be displayed, but I want to change the size of the grid on the fly. By selecting the ToolStripDropDownButton and selecting a predetermined list of grid sizes, the text of the ToolStripDropDownButton should change to show the user the new grid size.
Any answer is appreciated.
I have found the answer to my question, thank you all for the answers.
private void changeGridSizeDropDownButton_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
if (e.ClickedItem != null)
{
changeGridSizeDropDownButton.Text = e.ClickedItem.Text;
// This line converts my list gridsize options like 64, 32, and 16
// and Parses that text into the new selected gridsize.
gridSize = Int32.Parse(e.ClickedItem.Text);
}
}
It's easy you'll see.
myToolStripDropDownButton.DropDownItems[0].Text = "New grid size";
The index[0] is the first item in your DropBox
just change it to access other items.
This is to change the name of the items.
If you need to change Text somewhere on the ToolStrip
independently from your DropDownButton
check what item is selected than change
myToolStrip.Items.Add("DefautlGridSize");
myToolStrip.Items[0].Text("NewGridSize");
If you don't need the ToolStrip
especially I would consider using a ComboBox
with a Label
which would do the job much more simply.
Hope this helped