DataGridView的使用记录

首先初始化

DataGridView的使用记录
 1             this.CheckView.Columns.Clear();
 2             DataGridViewComboBoxColumn dcomo = new DataGridViewComboBoxColumn();
 3             dcomo.Items.Add("合格");
 4             dcomo.Items.Add("不合格");
 5             dcomo.Name = "combo";
 6             dcomo.HeaderText = "结论";
 7
 8             this.CheckView.Columns.Add("001", "表位号");
 9             this.CheckView.Columns.Add("002", "实验项目编号");
10             this.CheckView.Columns.Add(dcomo);
11
12
13             this.CheckView.Columns[0].Width = 150;
14             this.CheckView.Columns[1].Width = 150;
15             this.CheckView.Columns[2].Width = 150;
DataGridView的使用记录

生成数据

1             for (int i = 0; i < PointDT.Rows.Count; i++)
2             {
3                 int index = this.CheckView.Rows.Add();
4                 this.CheckView.Rows[index].Cells[0].Value = PointDT.Rows[i]["MeterNo"].ToString();
5                 this.CheckView.Rows[index].Cells[1].Value = PointDT.Rows[i]["TESTITEMID"].ToString();
6             }

也可使用

1             for (int i = 0; i < PointDT.Rows.Count; i++)
2             {
3                 int index = this.CheckView.Rows.Add();
4                 this.CheckView.Rows["001",i].Value = PointDT.Rows[i]["MeterNo"].ToString();
5                 this.CheckView.Rows["001",i].Value = PointDT.Rows[i]["TESTITEMID"].ToString();
6             }

获取下拉列表的数据

DataGridView的使用记录
 1                 for (int i = 0; i < CheckView.RowCount; i++)
 2                 {
 3                     if (CheckView["combo", i].Value.ToString().Trim()=="合格")
 4                     {
 5                         con = "1";
 6                     }
 7                     else
 8                     {
 9                         con = "2";
10                     }
11                     string sql = string.Format("update TestItem_Data_Temp SET CONCLUSION='{0}' WHERE EQUIPTYPE='{1}' AND EQUIPNO='{2}' and MeterNo='{3}'and TestItemID='80' ",con,(int)functionCommon.SysCommon.SysParam.EquipmentType, functionCommon.SysCommon.SysParam.ServerEquipNo, CheckView.Rows[i].Cells[0].ToString());
12                     cmd = new SqlCommand(sql, functionCommon.DbSmsDataTempCon);
13                     cmd.ExecuteNonQuery();
14                 }
上一篇:MVC中使用[ValidateAntiForgeryToken]防止CSRF 注入攻击


下一篇:【BZOJ 2242】[SDOI2011]计算器