Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check whether the item in the combo box is selected or not in C#?

I have a combo box in which I have to display the dates from a database. The user has to select a date from the combo box to proceed further, but I don't know how to make the user aware of selecting the item from the combo box first in order to proceed further.

What process should be followed so that a user can get a message if he has not selected the date from the combo?

like image 811
zoya Avatar asked Mar 17 '10 08:03

zoya


2 Answers

if (string.IsNullOrEmpty(ComboBox.SelectedText)) 
{
 MessageBox.Show("Select a date");
}
like image 79
Ashish Gupta Avatar answered Sep 18 '22 16:09

Ashish Gupta


Here is the perfect coding which checks whether the Combo Box Item is Selected or not:

if (string.IsNullOrEmpty(comboBox1.Text))
{
    MessageBox.Show("No Item is Selected"); 
}
else
{
    MessageBox.Show("Item Selected is:" + comboBox1.Text);
}
like image 22
Gokul Avatar answered Sep 21 '22 16:09

Gokul