Home > Back-end >  checkign multiple comboboxes and textboxes for content
checkign multiple comboboxes and textboxes for content

Time:09-27

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.

enter image description here

Cheers, TBZ

CodePudding user response:

For plain WinForms:

enter image description here

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!");
  }

}
}
  • Related