I'm trying to check a couple of comboboxes and textboxes if they have anything written or selected in them (via Buttonclick). Is there a compact solution, so that I don't have to write a messy code? Below is a picture of the interface in question.
Cheers, TBZ
CodePudding user response:
For plain WinForms:
You could handle the click-Event:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
var canExecute =
!string.IsNullOrWhiteSpace(this.textBox1.Text) &&
this.comboBox1.SelectedItem != null;
if (canExecute)
{
// do stuff
}
else
{
MessageBox.Show("Input missing!");
}
}
}