views:

708

answers:

2

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?

+2  A: 
Datagridview1.AutoGenerateColumns=false
ozczecho
how do i then assign my xml data to new columns i create?
Goober
DataGridViewColumn.DataPropertyName (http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcolumn.datapropertyname.aspx)
lc
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