Basically a button's tag property is the name of an existing combobox which I need to dynamically reference. It's a generic function to handle multiple buttons. Help
private void SQLButton(object sender, EventArgs e)
{
magic(((Button)sender).Tag.ToString());
}
private void magic(string currentcombo)
{
string CurrentText = (ComboBox).(currentcombo).Text;
}
You can set the Tag property to the actual ComboBox and avoid your problem altogether.
//code when defining your button...
{
sqlButton.Tag = comboBoxA; //instead of comboBoxA.Name
}
private void SQLButton(object sender, EventArgs e)
{
Button button = sender as Button;
ComboBox comboBox = button.Tag as ComboBox;
if (comboBox == null )
{...}
else
{
magic(comboBox);
}
}
private void magic(ComboBox currentcombo)
{
string CurrentText = currentcombo.Text;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With