简体   繁体   中英

C# Datagridview - Turn off AutoGenerateColumns when binding to XML file?

I am binding an XML file to a 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;

For binding the xml to a DataGridView do:

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.

Please read DataSet.ReadXml Method (String) for more information about loading xml into a dataset.

Other way of binding xml to Datagridview is deserializing the xml to a List<MyClass> and use it as BindingSource .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM