Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#组合框文本_C#_Xml_Combobox - Fatal编程技术网

C#组合框文本

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

目前,我有一个组合框,它由xml数据库的名称字段填充。我有以下代码来执行此操作:

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;
这将导致组合框没有初始选择