Solved

Winform combobox validate for empty string

Posted on 2012-04-05
3
1,147 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
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 500 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Loop not working 29 47
c# string handling 1 27
SQL Login 17 40
Crystal reports vb.net 2 16
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

920 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now