你的位置:首页 > ASP.net教程

[ASP.net教程]相关小知识点(来自小抽奖系统)


一、winform datagridview 知识点

1、自定义datagridview的行标题和列标题

DataTable dt = selectData();dgLDResult.DataSource = dt.DefaultView; #region 生成数据表格    /// <summary>    /// 生成数据表格    /// </summary>    /// <returns></returns>    private DataTable selectData()    {      List<string> lsDat = new List<string>();      DataTable dtData = new DataTable();      dtData.Columns.Add(new DataColumn("次数", typeof(string)));      dtData.Columns.Add(new DataColumn("抽奖结果"));      DataRow dr;      for (int i = 1; i < 13; i++)      {        dr = dtData.NewRow();        lsDat = sData(i);        StringBuilder sb = new StringBuilder();        if (i > 10)        {          string num = i.ToString().Substring(1, 1);          dr["次数"] = "现场抽奖第" + num + "轮";        }        else        {          dr["次数"] = "第" + i + "轮";        }        foreach (string num in lsDat)        {          sb.Append(num + ",");        }        if (!string.IsNullOrEmpty(sb.ToString()))        {          dr["抽奖结果"] = sb.ToString().Substring(0, sb.Length - 1);        }        dtData.Rows.Add(dr);      }      return dtData;    }     #endregion

View Code

2、填充datagridview表格的详细内容

#region 根据传入的i来筛选出数据    /// <summary>    /// 根据传入的i来筛选出数据    /// </summary>    /// <param name="i"></param>    /// <returns></returns>    private List<string> sData(int i)    {      List<string> lsWorkId = new List<string>();      DataSet ds = new DataSet();      try      {        oledCon = sqlHelper.OledCon();        oledCon.Open();        string sqlSelect = "select WorkId from LDResultList where Num=" + i;        oledDa = new OleDbDataAdapter(sqlSelect, oledCon);        oledDa.Fill(ds);      }      catch (Exception ex)      {        throw new Exception(ex.Message);      }      finally      {        oledCon.Dispose();        oledCon.Close();      }      foreach (DataRow dr in ds.Tables[0].Rows)      {        lsWorkId.Add(dr[0].ToString());      }      return lsWorkId;    }     #endregion

View Code

3、获取datagridview cheakboxColumn控件的值

dgLDResult.Rows[i].Cells[0].EditedFormattedValue.ToString()

 //用linq表示式      //var queryRows = from DataGridViewRow row in  dgLDResult.Rows       //        where (bool)row.Cells["xz"].Value      //        select row;

 

二、刷新窗体

 this.ShowResult_Load(sender, e);

三、绘制表格

 //private void DrawDT()    //{    //  int padding = 25;  //定义一个小格子的大小    //  Graphics g = CreateGraphics();    //  Pen pen = new Pen(Color .Green );  //画笔,里面的参数是画笔的颜色    //  //绘制横线    //  for (int i = 0; i < panel1 .Height / padding; i++)    //  {    //    g.DrawLine(pen, 0, padding * i, panel1.Width, padding * i);    //  }    //  //绘制竖线    //  for (int i = 0; i < panel1.Width / padding; i++)    //  {    //    g.DrawLine(pen, padding * i, 0, padding * i, panel1.Height);    //  }    //}