Michal_LFC
Michal_LFC

Reputation: 599

Access some data from list

I have a list that I created. I am uploading some data in it and then bind it to gridview. Code is bellow.

private void button7_Click(object sender, EventArgs e)
    {
        List<MyColumns> list = new List<MyColumns>();

        OpenFileDialog openFile1 = new OpenFileDialog();
        openFile1.Multiselect = true;

        if (openFile1.ShowDialog() != DialogResult.Cancel)
        {
            foreach (string filename in openFile1.FileNames)
            {
                using (StreamReader sr = new StreamReader(filename))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        string[] _columns = line.Split(",".ToCharArray());
                        MyColumns mc = new MyColumns();
                        mc.Time = _columns[0];
                        mc.System_Description = _columns[1];
                        mc.User_Description = _columns[2];
                        list.Add(mc);
                    }
                }
            }
            DataTable ListAsDataTable = BuildDataTable<MyColumns>(list);
            DataView ListAsDataView = ListAsDataTable.DefaultView;
            this.dataGridView1.DataSource = view = ListAsDataView;
            this.dataGridView1.AllowUserToAddRows = false;
            dataGridView1.ClearSelection();
        }
    }



class MyColumns
{
    public string Time { get; set; }
    public string System_Description { get; set; }
    public string User_Description { get; set; }
}

My question is if it is possible to access data from column System_Description? I would like to make some changes on this data. I mean I want to display it normally like this 3 columns, but maybe save in another list changed version of column System_Description?

Upvotes: 0

Views: 95

Answers (1)

Ehsan
Ehsan

Reputation: 32671

you can do this

List<string> description = youroriginalList
                          .Select(x=>x.System_Description).ToList<string>();

Upvotes: 2

Related Questions