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?
views:
708answers:
2how do i then assign my xml data to new columns i create?
Goober
2009-07-13 14:35:48
DataGridViewColumn.DataPropertyName (http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcolumn.datapropertyname.aspx)
lc
2009-07-13 14:38:36
A:
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
.
Vivek
2009-07-13 14:50:52