Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to put something in a text file into a datagrid using streamreader

What I have tried:

StreamReader reader = new StreamReader(ofdl.FileName);
          string content = reader.ReadToEnd();
          content = Regex.Replace(content, @"\n\s.+", "");
          reader.Close();
          List<code> codes = new List<code>();

          string s = content;
          string textvalues = s;
          foreach (var item in textvalues)
          {
              codes.Add(new code() { Value = item.ToString() });
          }
          dataGrid.ItemsSource = codes;


이 상태에서 어떻게 나아가야할지 모르겠따.
Posted
Updated 15-Dec-19 20:51pm

1 solution

The most likely reason it doesn't work is this line:
C#
foreach (var item in textvalues)
Since textvalues is a string, item will be a char - so you will add each individual non-whitespace character in the file to your grid separately.

Unless that's what you want, of course - in which case you will need to explain in much better detail exactly what problem you are having!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900