[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1277
  • Last Modified:

Winform combobox validate for empty string

I have a winform with 4 comboboxes. I used the IDE and "Items" and added the values manually to the combo box. 3 or 4 values in each combobox.

I open the form and nothing is selected. User has to selected something from the combox box. I have checked for "combo.SelectedValue", "combo.text", "combo.selectedtext", and "combo.selectedindex" . But, even when I select something from the dropdown, the values show as blank. I don't have an event or anything. I click a button and want to validate all combo boxes at the same time...

what do i need to do??
0
Camillia
Asked:
Camillia
1 Solution
 
Vikram Singh SainiSoftware Engineer cum AD DeveloperCommented:
Try combo.SelectedItem.ToString():

private void btnShow_Click(object sender, EventArgs e)
		{
			label1.Text = "Combobox 1: " + comboBox1.SelectedItem.ToString() +
				"Combobox 2: " + comboBox2.SelectedItem.ToString() +
				"Combobox 3: " + comboBox3.SelectedItem.ToString() +
				"Combobox 4: " + comboBox4.SelectedItem.ToString();
		}

Open in new window

0
 
BuggyCoderCommented:
to validate for empty string just add on click method and use this code:-

public void button1_click(object sender, EventArgs e)
{
if(IsValid())
{
//Button click processing here
}
else
{
//Validation Failure message here
}
}

private bool IsValid()
{
return (cmb1.Text!=String.Empty) && (cmb2.Text!=String.Empty);
}

Open in new window

0
 
CamilliaAuthor Commented:
let me try
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now