简体   繁体   中英

How to read .txt file into data gridview using c#?

so I'm new to c# and I was given an assignment (without being taught) to read a .txt file into a data gridview. I did it using StreamReader but it was rejected. It makes up 30% of my grade and I can't figure it out.
text file: 在此处输入图片说明

I'm required to put the date in one column, time in another, userID in another and the message in another. Almost any information will be helpful right about now

  1. You need to parse every line into an attribute of a Tuple. You could read the file a line at a time and split it by space as a delimiter.
  2. Create a list of tuples. Add every Tuple you have parsed into the list.
  3. Bind this collection to the ItemsSource property or DataSource property of the grid.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM