[英]C# Datagridview - Turn off AutoGenerateColumns when binding to XML file?
I am binding an XML file to a DataGridView
. 我将XML文件绑定到DataGridView
。 I don't want the columns to be auto-generated, in fact I want to generate them myself. 我不希望自动生成列,实际上我想自己生成它们。 Is there a way of turning off the auto generating columns feature and be able to programmatically create the columns myself? 有没有办法关闭自动生成列功能并能够以编程方式自己创建列?
Datagridview1.AutoGenerateColumns=false
As @ozczecho metioned do Datagridview1.AutoGenerateColumns=false;
正如@ozczecho提到的那样, Datagridview1.AutoGenerateColumns=false;
For binding the xml to a DataGridView do: 要将xml绑定到DataGridView,请执行以下操作:
myDataSet = new DataSet();
myDataSet.ReadXml("dataSetFriendly.xml");
myDataGridView.DataSource = myDataSet;
myDataGridView.DataMember = "dataSetFriendly";
In the designer create various columns and set the DataPropertyName
to the attribute/property name(s) from the Class that was used to generate the XML. 在设计器中,创建各列,并将DataPropertyName
设置为用于生成XML的类中的属性/属性名称。
Please read DataSet.ReadXml Method (String) for more information about loading xml into a dataset. 请阅读DataSet.ReadXml方法(字符串)以获取有关将xml加载到数据集中的更多信息。
Other way of binding xml to Datagridview
is deserializing the xml to a List<MyClass>
and use it as BindingSource
. 将xml绑定到Datagridview
另一种方法是将xml反序列化为List<MyClass>
并将其用作BindingSource
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.