Link to home
Start Free TrialLog in
Avatar of Victor  Charles
Victor CharlesFlag 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

SOLUTION
Avatar of chaau
chaau
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Victor  Charles

ASKER

Hi,

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

Thanks,

Victor
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank You.