?
Solved

Winform combobox validate for empty string

Posted on 2012-04-05
3
Medium Priority
?
1,244 Views
Last Modified: 2012-04-05
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
Comment
Question by:Camillia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 16

Expert Comment

by:Vikram Singh Saini
ID: 37813243
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
 
LVL 20

Accepted Solution

by:
BuggyCoder earned 2000 total points
ID: 37813460
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
 
LVL 7

Author Comment

by:Camillia
ID: 37813746
let me try
0

Featured Post

Automating Terraform w Jenkins & AWS CodeCommit

How to configure Jenkins and CodeCommit to allow users to easily create and destroy infrastructure using Terraform code.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question