DataGrid查看多个数据添加 [英] DataGrid View multiple data adding
本文介绍了DataGrid查看多个数据添加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想向数据网格视图添加更多详细信息.(添加更多数据行). dataGrid视图有3列.数据库源不支持数据.我从xml文件中获取数据.我正在尝试通过使用以下代码来做到这一点.
I want to add more details to a datagrid View .(add more data rows). there are 3 columns of the dataGrid View.Data are not support from a data base source. I get the data from a xml file. I''m trying to do this by using following code.
DataTable dt = new DataTable();
public void SyncWIthConfigFile()
{
initialXmlDoc();
XmlElement rootElement = xmlCommand.DocumentElement;
UFCCommand command = new UFCCommand();
foreach (XmlNode childNode in rootElement.ChildNodes)
{
List<ufccommand> commandList = new List<ufccommand>();
DataRow dr = dt.NewRow();
if (childNode.Name != "_ERD" && childNode.Name!="_DLY")
{
command.Name = childNode.Name;
dr["ColName"] = command.Name.ToString();
if (childNode.FirstChild.Name == "SET_RESPONSE")
{
command.SetValue = childNode.FirstChild.InnerText;
dr["ColSetValue"] = command.SetValue.ToString();
}
if(childNode.LastChild.Name=="GET_RESPONSE")
{
command.GetValue = childNode.LastChild.InnerText;
dr["ColGetValue"] = command.GetValue.ToString();
}
dataGridView1.DataSource = dt;
}
}
}</ufccommand></ufccommand>
运行此代码时,出现异常.
"Column ''ColName'' does not belong to table ."
但是我的第一个学术名称是"ColName".我无法理解错误.
When run this code there was an exception.
"Column ''ColName'' does not belong to table ."
But my first colunm name is"ColName". I can''t understand the wrong.
推荐答案
我找不到要向DataTable添加列的位置.
尝试将列添加到DataTable,然后再试一次.
例如:
DataTable表=新的DataTable();
table.Columns.Add("ColName",typeof(string));
table.Columns.Add("ColSetValue",typeof(string));
等等
I didn''t find where you are adding columns to the DataTable.
Try to Add columns to DataTable and try again it will work.
For Example:
DataTable table = new DataTable();
table.Columns.Add("ColName", typeof(string));
table.Columns.Add("ColSetValue", typeof(string));
etc
这篇关于DataGrid查看多个数据添加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文