• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C#dataGridView1添加数据和清空数据

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
    #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();


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap