Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6574953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:19:40+00:00 2026-05-25T15:19:40+00:00

I am trying to get my datagridview to display more than one row of

  • 0

I am trying to get my datagridview to display more than one row of data.

Every time I call the program it only writes the 1st line of data in the datagridview instead of adding it to a new row.

I have been looking on the forums for hours but combined with my inexperience I can not understand it.

The following code is in a loop and it reads an xml file each time. The goal is to put the xml data from each file into a new row in the table.

Public Sub ReadData(ByVal filename As String, ByVal file As String)
Try

 DS.ReadXml(filename)

 DS.Tables.Add("MyTable")
        With DS.Tables("MyTable")
            .Columns.Add("Title 1")
            .Columns.Add("Title 2")
            .Columns.Add("Title 3")
            .Columns.Add("Title 4")
            .Columns.Add("Title 5")
            .Columns.Add("Title 6")
        End With

        Using reader = New StreamReader(filename)
            Dim line As String = reader.ReadToEnd()
            rtb_Subsidary.AppendText(file & vbCrLf)
            DS.Tables("MyTable").Rows.Add(file, "test 1", "test 2", "test 3", "test 4", "test 5", "test 6")
        End Using

        With dgv_Lic
            .DataSource = DS.Tables("MyTable")
            .ReadOnly = True
            .ScrollBars = ScrollBars.Vertical
            .AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
            .AutoResizeColumns()
            .RowHeadersVisible = False
            For Each col As DataGridViewColumn In .Columns
                col.SortMode = DataGridViewColumnSortMode.NotSortable
            Next
        End With



...end code
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:19:41+00:00Added an answer on May 25, 2026 at 3:19 pm

    It looks like the logic flow of your xml reading isn’t quite right. Also the reading of the xml doesn’t look correct. The rest of what you are doing looks ok but the order you have your statements in (and the xml reading) in means they don’t end up doing quite what you want.

    My reading of the steps of your current code is:

    1. For each xml file call read data
    2. Create or at least re-initialize the dataset
    3. Read your xml into a string variable (but you don’t do anything with it)
    4. Add a single row to the dataset (it isn’t clear what rtb_Subsidary.AppendText(file & vbCrLf) does)
    5. Overwrite the datasource of the DataGridView with the newly initialized DataTable (which due to the back xml reading only has one line

    My VB.Net is very rusty so rather than giving you some code that won’t work (or some c#) here is a piece of pseudo code that should see you on the right way.

    1. Do not initialize your table in the read data method – create the table elsewhere and also assign it as the DataGridView datasource elsewhere
    2. In read data in the readdata method in to a temp table and then use DataTable.Merge to combine this new data with your old data.

    So, in very poor VB like pseudo code:

    Public Class Form1
    
        // A private class level variable of type datatable
        Private dt As New DataTable    
    
        // You forms constructor       
        Public Sub New()
    
            InitializeComponent()
    
            // You may be able to get away with this initialization by using it automatically from the xml only once
            With td
              .Columns.Add("Title 1")         
              .Columns.Add("Title 2")         
              .Columns.Add("Title 3")         
              .Columns.Add("Title 4")         
              .Columns.Add("Title 5")         
              .Columns.Add("Title 6")         
            End With 
    
            // Also have you DataGridView code here in the initialization section
            With dgv_Lic           
                .DataSource = DS.Tables("MyTable")           
                .ReadOnly = True           
                .ScrollBars = ScrollBars.Vertical           
                .AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill           
                .AutoResizeColumns()           
                .RowHeadersVisible = False           
                For Each col As DataGridViewColumn In .Columns           
                    col.SortMode = DataGridViewColumnSortMode.NotSortable           
                Next           
            End With 
    
        End Sub
    
        // And this is your ReadData method called for each file
        Public Sub ReadData(ByVal filename As String)
            // Local datatable
            Dim dt_temp As New DataTable
    
            Using reader = New StreamReader(filename)                 
                dt_temp.ReadXml(reader)
            End Using  
    
            // Now merge dt with   
            dt.Merge(dt_temp)          
        End Sub
    End Class
    

    As an aside – for this sort of problem a debugger (as you have in Visual Studio) can be great, it allows you to step through the execution of your application line by line seeing exactly what is going on.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get a changed currentcell event in DataGridView , but every time
I'm trying to get a DataGridView to display the HeaderText from the row and
I was trying to get the row count of a DataGridView [ dataGridView1.Rows.Count ].
I am trying to get the DataGridView to render the insert new row row
I'm trying to get the user entered data in a windows forms datagridview to
I'm trying to get a basic DataGridView to insert new rows into a table.
I am trying to get the sorting to work for the DataGridView. The sorting
I am trying to get a fuzzy search working on a datagridview that is
I'm trying to get my current program to take information from a dynamically created
I'm trying to hack together a datagridview in c# that can handle hierarchical data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.