相關小知識點(來自小抽獎系統)

1、winform datagridview 知識點sql

一、自定義datagridview的行標題和列標題ide

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

二、填充datagridview表格的詳細內容ui

#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

三、獲取datagridview cheakboxColumn控件的值this

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

 

2、刷新窗體spa

 this.ShowResult_Load(sender, e);

3、繪製表格code

 //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);
        //    }
        //}
相關文章
相關標籤/搜索