Link to home
Create AccountLog in
Avatar of pointeman
pointemanFlag for United States of America

asked on

Combobox Empty Rows Prevention?

Q. Anyone know how to fill a ComboBox without empty rows?

I'm using a dataset and sorting the Combobox like so:

    comboBox1.Sorted = true;

   foreach (DataRow row in dataSet1.Tables[0].Rows)
   {
        comboBox1.Items.Add(row["LastName"]);
   }          
ASKER CERTIFIED SOLUTION
Avatar of mrjoltcola
mrjoltcola
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of pointeman

ASKER

This works quite well, thanks for the advice...

if (!string.IsNullOrEmpty(row["LastName"].ToString()))
     comboBox1.Items.Add(row["LastName"].ToString());