zoukankan      html  css  js  c++  java
  • C# dataGridView1 添加数据 和清空数据

        #region MyRegion
    
                DataGridViewTextBoxColumn col = new DataGridViewTextBoxColumn();
    
                DataGridViewTextBoxColumn col1 = new DataGridViewTextBoxColumn();
    
                DataGridViewTextBoxColumn col2 = new DataGridViewTextBoxColumn();
    
                DataGridViewTextBoxColumn col3 = new DataGridViewTextBoxColumn();
    
                DataGridViewTextBoxColumn col4 = new DataGridViewTextBoxColumn();
    
                DataGridViewImageColumn col5 = new DataGridViewImageColumn();
    
    
                DataGridViewTextBoxCell celltext = new DataGridViewTextBoxCell();
    
                DataGridViewImageCell cellimage = new DataGridViewImageCell();
    
                col.CellTemplate = col1.CellTemplate = col2.CellTemplate = col3.CellTemplate = col4.CellTemplate = celltext;
    
                col5.CellTemplate = cellimage;
    
                col.HeaderText = "名称";
    
                col1.HeaderText = "分类";
    
                col2.HeaderText = "数量";
    
                col3.HeaderText = "价格";
    
                col4.HeaderText = "销售时间";
    
                col5.HeaderText = "图片";
    
                dataGridView1.Columns.Add(col);
    
                dataGridView1.Columns.Add(col1);
    
                dataGridView1.Columns.Add(col2);
    
                dataGridView1.Columns.Add(col3);
    
                dataGridView1.Columns.Add(col4);
    
                dataGridView1.Columns.Add(col5);
                //--
                DataGridViewRow row = new DataGridViewRow();
    
                int index = dataGridView1.Rows.Add(row);
    
                dataGridView1.Rows[index].Cells[0].Value = "0001";
    
                dataGridView1.Rows[index].Cells[1].Value = "0002";
    
                dataGridView1.Rows[index].Cells[2].Value = "0003";
    
                dataGridView1.Rows[index].Cells[3].Value = "0004";
    
                dataGridView1.Rows[index].Cells[4].Value = "0005";
    
                // dataGridView1.Rows[index].Cells[5].Value = "";// Image.FromFile();
    
                #endregion

    this.dataGridView1.Columns.Add("0","001");//添加列
    this.dataGridView1.Columns.Add("0", "002");
    this.dataGridView1.Columns.Add("0", "003");
    this.dataGridView1.Rows.Add("第一个字段值", "第二个字段值", "第三个字段值");

    DataTable dt = (DataTable)dataGridView1.DataSource;
    //dt.Rows.Count
    //dt.Columns.Count
    //if (dt != null&&dt.Rows.Count > 0 )
    //{
    // dt.Columns.Clear();
    // dt.Rows.Clear();
    // dataGridView1.DataSource = dt;
    //}
    dataGridView1.Columns.Clear();
    dataGridView1.Rows.Clear();

  • 相关阅读:
    构建之法第十三~十七章阅读
    构建之法第十,十一,十二章阅读
    构建之法第八,九,十章阅读
    Sprint会议计划
    作业6
    作业5 四则运算 测试与封装 5.2
    作业5 四则运算 测试与封装 5.1
    构建之法2
    做汉堡
    构建之法阅读
  • 原文地址:https://www.cnblogs.com/enych/p/9246546.html
Copyright © 2011-2022 走看看