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

  • Home
  • SEARCH
  • 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 4338198
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:02:58+00:00 2026-05-21T11:02:58+00:00

I am trying to populate a datagrid from a .txt file. I managed to

  • 0

I am trying to populate a datagrid from a .txt file. I managed to do it with the split function Split(sr.ReadLine, ” “) when I have all the rows identical with only one space, but the problem I have is that the txt file is not delimited and the “spaces” varies some time. This is a sample of my data:

Col1  Col2 Col3
1      Mary Yes
1234   John Yes
999    Leo No

So my question is how to delimit or split the line based when it finds the next character and ignore the empty spaces. This is the code I have.

OpenFileDialog1.Filter = "Text File|*.txt"
    OpenFileDialog1.Title = "Open File..."
    OpenFileDialog1.FileName = "test"

    If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
        Dim sr As System.IO.StreamReader = New System.IO.StreamReader(OpenFileDialog1.FileName)
        Dim srlineitems() As String
        srlineitems = Split(sr.ReadLine, " ")

        Dim DT As New DataTable
        DT.Columns.Add("Col1")
        DT.Columns.Add("Col2")
        DT.Columns.Add("Col3")
        DT.Columns.Add("Col4")

        DataGridView1.DataSource = DT

        Dim Lines() As String = System.IO.File.ReadAllLines(OpenFileDialog1.FileName)

        For Each Line As String In Lines
            Dim ItemsOf() As String = Split(Line, " ")
            Dim NRow As String() = {ItemsOf(0), ItemsOf(1), ItemsOf(2), ItemsOf(3)}

            DT.Rows.Add(NRow)

        Next Line


    End If  

Any help is appreciated

  • 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-21T11:02:59+00:00Added an answer on May 21, 2026 at 11:02 am

    Try the .Net String.Split method instead, it has a RemoveEmptyEntries option.

    ItemsOf = Line.Split(New String() {" "},
        StringSplitOptions.RemoveEmptyEntries)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new at this. I am trying to populate a datagrid from a
I'm trying to populate an xml file into a Delphi ListView1, then group all
I am trying to populate a collection with data from a JSON file. I'm
I've got a DataGrid with 6 columns: ComboBox;ComboBox;CheckBox;CheckBox;CheckBox;TextBox I'm trying to populate this DataGrid
I am trying to build a DataTable to populate a DataGrid in VB.NET. The
I am trying populate H3 with the sum of column E for rows that
I am trying to populate a dependency property from XAML. The dependency property is
I'm trying to populate this list with strings from the object data. It comes
I have created a sample silverlight application and trying to populated DataGrid with Data
im trying to populate my listview beneath my tab function but for some reason

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.