csv - C# : Split String and put it in the first column of a DataGridView -
i need take first line of file , put words of string first column of datagridview.
i have written code csv file converted array list:
arraylist filelist = new arraylist(); private void button2_click(object sender, eventargs e) { string line; // read file , display line line. //read path textbox system.io.streamreader file = new system.io.streamreader(textbox1.text); stringfordata=file.readline(); //this line because didn't need //the first //line of file while ((line = file.readline()) != null) { // puts elements array filelist.add(line.split(';')); } file.close(); }
my file :
name;surname;telephone;address; george;parado;3434;lili_2; jennifer;macin;3333;powel_34; nick;lukas;3322;manchester_44;
i want datagridview :
**subject type** name surname telephone address
so need take first line of file , put first column of datagridview.
as far have made method.
arraylist fordata = new arraylist(); string stringfordata; public void todatagrid() { datagridviewcolumn newcol = new datagridviewtextboxcolumn(); fordata.add(stringfordata.split(';')); }
the method todatagrid must put elements of arraylist named fordata first column of datagridview.
please help!!
the code below takes delimited string, splits , adds values datagridview column. though i'm still struggling see why want this.
string csv = "name,surname,telephone,address"; string[] split = csv.split(','); datagridviewtextboxcolumn subject = new datagridviewtextboxcolumn(); subject.headertext = "subject type"; subject.name = "subject"; datagridview1.columns.add(subject); foreach (string item in split) { datagridview1.rows.add(item); }
Comments
Post a Comment