Results 1 to 12 of 12

Thread: [RESOLVED] Populating a Datafield Grid

Hybrid View

  1. #1
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: Populating a Datafield Grid

    i was assuming you'd use a text file with a header row as the first row containing the text you want displayed as your dgv column headers. if you just want standard columnheaders:

    vb Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         Dim lines() As String = IO.File.ReadAllLines("I:\test.txt")
    3.         Dim dt As New DataTable
    4.        
    5.         For x as integer = 1 to lines(0).split(cchar(vbtab)).length
    6.             dt.Columns.Add("Column" & x.tostring)
    7.         Next
    8.         For x As Integer = 0 To lines.GetUpperBound(0)
    9.             Dim dr As DataRow = dt.NewRow
    10.             dr.ItemArray = lines(x).Split(cchar(vbtab))
    11.             dt.Rows.Add(dr)
    12.         Next
    13.                
    14.         DataGridView1.DataSource = dt
    15.  
    16.     End Sub
    17. End Class

  2. #2

    Thread Starter
    New Member
    Join Date
    Nov 2010
    Posts
    11

    Re: Populating a Datafield Grid

    exactly what i was hoping for.
    thanks so much paul

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width