0
votes

Step 1:

DataSet dsMain = new DataSet();
dsMain.ReadXml(my xml path);

Results I got 36 datatable in that dsMain dstaset.

Step 2:

Dynamically created 36 DataGridView to display all datatable. It results some DataGridView has table but no data. And some columns were missing. Reason those columns are auto generated Mapping column. And it column name like TabelName_Id.

Step 3:

for (int index = 0; index < ds1.Tables.Count; index++)
{
    DataTable dtnew = ds1.Tables[index].Copy();

    for (int ColCount = 0; ColCount < dtnew.Columns.Count; ColCount++)
    {
        if (dtnew.Columns[0].ColumnMapping == MappingType.Hidden)
        {
            dtnew.Columns[0].ColumnMapping = MappingType.Element;
        }
    }
}

Now that column is get visible. But my problem is I could not get parent auto generated column.

Example:

Tabel 1: Parent-> Columns(Parent_Id,Col1,Col2,Col3)

Tabel 2: Child -> Columns(Child_Id,Col1,Col2,Col3,Parent_Id)

after following step 3 I able to see Child_Id in Child table but I couldn't able to see Parent_Id in Child table.

Please help me get out of this.

My sample xml

<Parent value="25">
<Child>
<Inner></Inner>
</Child>
</Parent>
1

1 Answers

2
votes

In the for loop, your index is always 0. did you mean to use ColCount?

for (int ColCount = 0; ColCount < dtnew.Columns.Count; ColCount++)
{
   if (dtnew.Columns[ColCount].ColumnMapping == MappingType.Hidden)
   {
      dtnew.Columns[ColCount].ColumnMapping = MappingType.Element;
   }
}

what does the above change do to your results? if you still see the parent/child issues, we can look further.