C#组合框文本
目前,我有一个组合框,它由xml数据库的名称字段填充。我有以下代码来执行此操作:C#组合框文本,c#,xml,combobox,C#,Xml,Combobox,目前,我有一个组合框,它由xml数据库的名称字段填充。我有以下代码来执行此操作: XmlDocument xmlReturnDoc = new XmlDocument(); xmlReturnDoc.Load("Data.xml"); XmlNodeList xnList = xmlReturnDoc.SelectNodes("/Students/Student"); foreach (XmlNode xn in xnList) { string firstName = xn["FirstNam
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"; }
这将填充“组合框”下拉列表,唯一的问题是我希望原始字段留空,如何执行此操作?组合框将在通过数据绑定可用后选择第一项。您可以在以后进行设置:
NewLessonStudentComboBox.SelectedIndex = -1;
这将导致组合框没有初始选择。一旦通过数据绑定可用,组合框将选择第一项。您可以在以后进行设置:
NewLessonStudentComboBox.SelectedIndex = -1;
这将导致组合框没有初始选择