First, WinForm DataGridView knowledge Points
1. Custom DataGridView row and column headings
DataTable dt =selectdata ();d Gldresult.datasource=dt. DefaultView; #regionGenerate Data tables/// <summary> ///Generate Data Tables/// </summary> /// <returns></returns> PrivateDataTable Selectdata () {List<string> Lsdat =Newlist<string>(); DataTable Dtdata=NewDataTable (); DTDATA.COLUMNS.ADD (NewDataColumn ("number of",typeof(string))); DTDATA.COLUMNS.ADD (NewDataColumn ("Lottery Results")); DataRow Dr; for(inti =1; I < -; i++) {Dr=Dtdata.newrow (); Lsdat=SData (i); StringBuilder SB=NewStringBuilder (); if(I >Ten) { stringnum = i.ToString (). Substring (1,1); dr["number of"] ="Live Draw No."+ num +"Wheel"; } Else{dr["number of"] ="Section"+ i +"Wheel"; } foreach(stringNuminchLsdat) {sb. Append (Num+","); } if(!string. IsNullOrEmpty (sb.) ToString ())) {dr["Lottery Results"] = sb. ToString (). Substring (0, SB. Length-1); } dtData.Rows.Add (DR); } returnDtdata; } #endregion
View Code
2. Fill in the details of the DataGridView form
#regionFilter out data based on incoming I/// <summary> ///filter out data based on incoming I/// </summary> /// <param name= "i" ></param> /// <returns></returns> Privatelist<string> SData (inti) {List<string> Lsworkid =Newlist<string>(); DataSet DS=NewDataSet (); Try{Oledcon=Sqlhelper.oledcon (); Oledcon.open (); stringSqlselect ="Select WorkID from ldresultlist where num="+i; Oledda=NewOleDbDataAdapter (Sqlselect, Oledcon); Oledda.fill (DS); } Catch(Exception ex) {Throw NewException (ex. Message); } finally{oledcon.dispose (); Oledcon.close (); } foreach(DataRow DrinchDs. tables[0]. Rows) {Lsworkid.add (dr[0]. ToString ()); } returnLsworkid; } #endregion
View Code
3. Get the value of the DataGridView Cheakboxcolumn control
Dgldresult.rows[i]. cells[0]. Editedformattedvalue.tostring ()
// using LINQ expressions // var queryrows = from DataGridViewRow row in dgldresult.rows // where (bool) row. cells["XZ"]. Value // select row;
Second, refresh the form
this. Showresult_load (sender, E);
Iii. Drawing of forms
//private void Drawdt ()//{ //int padding = 25; //define the size of a small lattice//Graphics g = creategraphics (); //Pen pen = new Pen (Color. Green); //The brush, the parameter inside is the color of the brush// //Draw Horizontal lines//for (int i = 0; i < Panel1. height/padding; i++)// { //G.drawline (pen, 0, padding * I, panel1. Width, padding * i); // } // //draw a vertical line//for (int i = 0; i < Panel1. width/padding; i++)// { //g.drawline (pen, padding * I, 0, padding * I, panel1. Height); // } //}
Related trivia points (from the Small lottery system)