我在向数据网格中的组合框添加文本时遇到问题。我有问题评论说这是错误的。如果有人能告诉我正确的方法,谢谢。
注意:所有其他信息都是正确的。
这是代码。
XmlNode node = doc.SelectSingleNode("/MovieData");
foreach (XmlNode movie in node.SelectNodes("Movie"))
{
if (movie != null)
{
DataGridViewRow row = (DataGridViewRow)movieListDataViewBox.Rows[0].Clone();
row.Cells[0].Value = movie["Name"].InnerText;
row.Cells[1].Value = movie["Rating"].InnerText;
row.Cells[2].Value = movie["Disk"].InnerText;
row.Cells[3].Value = movie["LengthHr"].InnerText + " Hr. " + movie["LengthMin"].InnerText + " Min.";
// clear the combobox here ?
foreach(XmlNode type in movie["Type"])
{
row.Cells[4].Value = type.InnerText; // This is wrong here
}
row.Cells[5].Value = movie["SeriesType"].InnerText;
row.Cells[6].Value = movie["Location"].InnerText;
row.Cells[7].Value = movie["Owner"].InnerText;
row.Cells[8].Value = movie["Date"].InnerText;
row.Cells[9].Value = movie["Time"].InnerText;
movieListDataViewBox.Rows.Add(row);
}
}
编辑:这是 xml 文件的外观。
<Movie>
<Name>Death Race</Name>
<Type>Action</Type>
<Type>Adventure</Type>
<Rating>R</Rating>
<Disk>Blu-Ray</Disk>
<Owner>N/A</Owner>
<Location>Basement</Location>
<SeriesType>Movie Series</SeriesType>
<LengthHr>1</LengthHr>
<LengthMin>51</LengthMin>
<Time>9 : 44 : 23 PM</Time>
<Date>10/16/2013</Date>
</Movie>
<Movie>
<Name>Death Race 2</Name>
<Type>Action</Type>
<Type>Adventure</Type>
<Rating>R</Rating>
<Disk>Combo</Disk>
<Owner>N/A</Owner>
<Location>Basement</Location>
<SeriesType>Movie Series</SeriesType>
<LengthHr>1</LengthHr>
<LengthMin>41</LengthMin>
<Time>9 : 52 : 34 PM</Time>
<Date>10/16/2013</Date>
</Movie>