list<string> item =Newlist<string>(); Item. ADD ("first column of data"); Item. ADD ("second column of data"); Item. ADD ("third column of data"); Item. ADD ("Column Fourth Data"); Item. ADD ("Column Fifth Data"); Item. ADD ("column Sixth data"); Item. ADD ("column Seventh Data"); Item. ADD ("column Eighth Data"); Item. ADD ("Column Nineth Data"); DataTable DT=NewDataTable (); Dt. Columns.Add ("Name one"); Dt. Columns.Add ("name Two"); DataRow Dr=dt. NewRow (); for(inti =0; I < item. Count; i+=2) { //If this is not instantiated every time, the data in the loop will overwrite the lastDr =dt. NewRow (); //write to the specified columndr["Name one"] =Item[i]; //Judging if it's an odd number, the last column is not assigned . if((i+1) <item. Count) {dr["name Two"] = Item[i +1]; } dt. Rows.Add (DR); } //finally bind to the DataGridView to become the data source is OK This. dgvshow.datasource = DT;
DataTable puts a list of data into two colum to prevent channeling