Chris2222000 Chris2222000 - 7 months ago 31 Question

Visual Basic - read xml error "child list for field cannot be created"

I'm attempting to create a small desktop application (using Visual Studio) that reads xml files from a games resource files. These files are stored in XML. When I try to read the file into a datagridview I receive an error:

System.ArgumentException: Child list for field SpaceUnitsCapital cannot be created.
at System.Windows.Forms.BindingContext.EnsureListManager(Object dataSource, String dataMember)
at System.Windows.Forms.DataGridView.DataGridViewDataConnection.SetDataConnection(Object dataSource, String dataMember)
at System.Windows.Forms.DataGridView.set_DataMember(String value)
at SWFOC.Form1.clk(Object sender, EventArgs e) in C:\Users\Number6\documents\visual studio 2012\Projects\SWFOC\SWFOC\Form1.vb:line 37

The code im using to attempt this is:

Dim URL As String = "C:\Program Files (x86)\LucasArts\Star Wars Empire at War Forces of Corruption\Data\XML\Spaceunitscapital.xml"
Dim ds As DataSet = New DataSet()
Dim fsReadXml As System.IO.FileStream = New System.IO.FileStream(URL, System.IO.FileMode.Open)

DataGridView1.DataSource = ds
DataGridView1.DataMember = "SpaceUnitsCapital"
Catch Err As Exception
RichTextBox1.Text = Err.ToString
End Try

Here is a sample of what the xml files look like:

<?xml version="1.0"?>

<SpaceUnit Name="Calamari_Cruiser">
<Encyclopedia_Good_Against> Victory_Destroyer Acclamator_Assault_Ship Interceptor4_Frigate </Encyclopedia_Good_Against>
<Encyclopedia_Vulnerable_To> TIE_Bomber Skipray_Blastboat </Encyclopedia_Vulnerable_To>
<GUI_Row> 1 </GUI_Row>
<MovementClass> Space </MovementClass>
<Space_Layer> Capital </Space_Layer>
<OverrideAcceleration> .02 </OverrideAcceleration>
<OverrideDeceleration> .02 </OverrideDeceleration>

<Armor_Type> Armor_Calamari_Cruiser </Armor_Type>

If I attempt to run the code without the line that fills the datamember it does not throw an error but it also doesn't do anything else. It never populates the DGV.

Does anyone know how I can avoid this error? The end result is to somehow populate the fields into the app in some form so that they can then be edited and saved so I am open to other methods if anyone has any ideas.

Thanks in advance,


Based on your comments and since my comment worked I repeat my solution here:

DataGridView1.DataSource = ds.Tables(0)

Your question why my code worked is actually a question regarding the difference between a dataset and a datatable.
You can consider that a dataset is a set of datatables, or in other words imagine dataset something like a database and the datatable a table in that database.
So you should set as a datasource to your grid a datatable and not a set of tables