winforms - Bind list to gridview C# -


i'm trying bind list gridview. situation this: take data .txt file, later put inside first list list<mycolumns>. have data in list (with 3 separated columns) created. taking data 1 of columns called system_description. show data in gridview, thing length of each row. how should fix it? here code.

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();         }          list<string> description = list.select(x => x.system_description).tolist<string>();         this.datagridview2.datasource = description;      } class mycolumns {     public string time { get; set; }     public string system_description { get; set; }     public string user_description { get; set; } } 

edit:

i've read databind() works web form, app desktop app. should now?

this.datagridview1.datasource = new bindingsource(list);


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -