1 Replies - 6068 Views - Last Post: 08 September 2012 - 01:06 PM Rate Topic: -----

#1 blue jhon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 21-July 12

VB.Net read a text file and show Data after (:) in datagridview

Posted 08 September 2012 - 10:29 AM

I have got a assignment. I have a folder which have some text file. In the text file there have some students info such as fathers name, mothers name, contact number etc. And every text file name is like 'AddressBook_038'. here 038 is the roll number. It is different for every students.
My assignment is there have a textfile and a browse button. There also have a datagrid view. Datagridview column is roll, fathers name, mothers name, contact number. I have to create such program that when I click browse button and select the folder the data automatically show in datagrid view. Such as in the roll column only show the roll. Program automatically read the text file name and input the data after (_) in the roll column. Then it read the info from the text file and show data after (:) in the others column.
I don't understand how I can do this? I do something which I give it bellow:

OpenFD.InitialDirectory = "C:\"
        OpenFD.Title = "Open your Floder"
        Dim didwork As Integer = OpenFD.ShowDialog()




I need the help of someone expert.

Attached image(s)

  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: VB.Net read a text file and show Data after (:) in datagridview

#2 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1623
  • View blog
  • Posts: 5,200
  • Joined: 25-September 09

Re: VB.Net read a text file and show Data after (:) in datagridview

Posted 08 September 2012 - 01:06 PM

After struggling to read your post I will leave you with this much:
StreamReader will help you read the text file
String.Split will help you parse the text that you read in

  • Open the file with a StreamReader object.
  • Add a row to the datagridview
  • Read a line of the file and split it at the :
  • place the result from the split array into its appropriate column.
  • Repeat for each line until there are no more lines in the stream.


The code you've given doesn't even come close to showing any effort on achieving this task.
Read up on the things I've listed, make an attempt at it and when you get stuck, post where you're still having issues.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1