tags:

views:

193

answers:

1

At the moment I have a combobox that is populated from the name fields of a xml database. I have the following code to do this:

XmlDocument xmlReturnDoc = new XmlDocument();
xmlReturnDoc.Load("Data.xml");
XmlNodeList xnList = xmlReturnDoc.SelectNodes("/Students/Student");
foreach (XmlNode xn in xnList)
{ string firstName = xn["FirstName"].InnerText;
  string middleInitial = xn["MiddleInitial"].InnerText;
  string lastName = xn["LastName"].InnerText;
  NewLessonStudentComboBox.DataSource = Students;
  NewLessonStudentComboBox.DisplayMember = "DisplayName"; }

This populates the combobox drop down, the only thing is I want the original field left blank, how do I do this?

+3  A: 

A ComboBox will select the first item once it's available though databinding. You can set it afterwards:

NewLessonStudentComboBox.SelectedIndex = -1;

This will cause the ComboBox to have no initial selection.

Joey
Perfect, thank you!
The Woo