Hi,
You don't have to save values to another file. You can load them to collection (like List) in memory and then bind to DataGridView. Here you have some sample:
if (!File.Exists(txtSelFile.Text))
{
throw new FileNotFoundException();
}
string[] lines = File.ReadAllLines(txtSelFile.Text);
string BC = string.Empty;
string PrevBcode = string.Empty;
List<string> barcodes = new List<string>();
foreach(string s in lines)
{
string[] fname1 = s.Split('|');
if (fname1[0] == "AAA")
{
BC = fname1[2];
if (BC != PrevBcode)
{
PrevBcode = fname1[2];
barcodes.Add(BC);
}
}
}
dataGridView1.DataSource = barcodes.Select(x => new { Value = x }).ToList();</string></string></string></string>
Another solution is to create class for storing string values like this one (save it in StringValueClass.cs file in your project:
public class StringValueClass
{
public string StringValue { get; set; }
public StringValueClass(string value)
{
StringValue = value;
}
}
And modify your data loading code:
List<StringValueClass> barcodes = new List<StringValueClass>();
foreach (string s in lines)
{
string[] fname1 = s.Split('|');
if (fname1[0] == "AAA")
{
BC = fname1[2];
if (BC != PrevBcode)
{
PrevBcode = fname1[2];
barcodes.Add(new StringValueClass(BC));
}
}
}
dataGridView1.DataSource = barcodes;
If you added column in DataGridView component, make sure that column has set DataPropertyName set to: StringValue
Good start for learning about collections is MSDN:
http://msdn.microsoft.com/en-us/library/system.collections.generic%28v=vs.110%29.aspx[
^]
Instead of using textbox control to get file path you may consider using OpenFileDialog:
http://msdn.microsoft.com/en-us/library/system.windows.forms.openfiledialog%28v=vs.110%29.aspx[
^]
I hope you find this useful.