im having a combo box in which i have to display dates from database...user have to select a date from the combo box to proceed further...but im not able to make the user aware of selecting the item from the combo box first to proceed further...what is the process so that a user can get a message if he has not selected the date from the combo..
A:
check the text property like this
if (combobox.text != String.Empty)
{
//continue
}
else
{
// error message
}
Wael Dalloul
2010-03-17 08:37:35
+3
A:
if (cboDate.SelectedValue!=null)
{
//there is a selected value in the combobox
}
else
{
//no selected value
}
RJ1516
2010-03-17 08:45:51
A:
You can use SelectedIndex
or SelectedItem properties of the ComboBox
.
Andrew Bezzub
2010-03-17 08:47:00
+1
A:
if (string.IsNullOrEmpty(ComboBox.SelectedText))
{
MessageBox.Show("Select a date");
}
ydobonmai
2010-03-17 08:47:05
+1
A:
You'll want to use DropDownStyle = DropDownList so you can easily make sure that the user picked an entry from the list and can't type random text in the box. Add an empty item to Items before you populate it (or "Please select"). Now, the default is automatically empty and the test is simple: just check that SelectedIndex > 0.
Hans Passant
2010-03-17 09:00:56