Avatar of Victor  Charles
Victor Charles
Flag for United States of America asked on

Help with adding data to DataTable

Hi,

I'm using the code below to create an xml file with data only for visible columns in the Grid, but when I export the file the xml file contains data in the invisible columns, how do I fix this error? For example data in columns 1 to 10 is included in dtNew2 eventhough they don't appear in the C1Screen2.

For i As Integer = 1 To 10
            Me.C1Screen2.Splits(0).DisplayColumns(i).Visible = False
        Next
        For i = 26 To 50
            Me.C1Screen2.Splits(0).DisplayColumns(i).Visible = False
        Next

        Dim dtnew2 As New DataTable
        ds.Tables.Clear()
        For col As Integer = 0 To C1Screen2.Splits(0).DisplayColumns.Count - 1
            If C1Screen2.Splits(0).DisplayColumns(col).Visible = True Then

                dtnew2.Columns.Add(C1Screen2.Splits(0).DisplayColumns(col).Name, C1Screen2.Columns(col).DataType)

                MsgBox(C1Screen2.Columns(col).Text)
            End If
        Next
        For row = 0 To C1Screen2.Splits(0).Rows.Count - 1
            dtnew2.Rows.Add(dtnew2.NewRow())

            For col As Integer = 0 To C1Screen2.Splits(0).DisplayColumns.Count - 1
                If C1Screen2.Splits(0).DisplayColumns(col).Visible = True Then

                    For col1 As Integer = 0 To dtnew2.Columns.Count - 1
                        If C1Screen2.Splits(0).DisplayColumns(col).Visible = True Then
                            dtnew2.Rows(row)(col1) = C1Screen2(row, col1)
                        End If
                    Next
                End If
            Next

        Next

        ds.Tables.Add(dtnew2)
        ds.Tables(0).WriteXml(Application.StartupPath + "\AOP40SC2d.xml")

Open in new window

Visual Basic.NET.NET Programming

Avatar of undefined
Last Comment
Victor Charles

8/22/2022 - Mon
SOLUTION
chaau

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Victor Charles

ASKER
Hi,

Can you please send me an example using Copy().

Thanks,

Victor
ASKER CERTIFIED SOLUTION
Nasir Razzaq

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Victor Charles

ASKER
Thank You.
Your help has saved me hundreds of hours of internet surfing.
fblack61