2009-11-03 78 views
0

目前我有一个组合框从xml数据库的名称字段填充。我有以下的代码来做到这一点:C#组合框文本

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"; } 

这将填充组合框下拉,唯一的事情是我想要的原始字段留白,我该怎么办呢?

回答

3

ComboBox在通过数据绑定可用时将选择第一个项目。你可以设置它:

NewLessonStudentComboBox.SelectedIndex = -1; 

这将导致组合框没有初始选择。

+0

完美,谢谢! – 2009-11-03 22:51:05