#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[].Value = ""; dataGridView1.Rows[index].Cells[].Value = ""; dataGridView1.Rows[index].Cells[].Value = ""; dataGridView1.Rows[index].Cells[].Value = ""; dataGridView1.Rows[index].Cells[].Value = ""; // 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();

C# dataGridView1 添加数据 和清空数据的更多相关文章

  1. C# DataGridView控件绑定数据后清空数据

    //1.this.dataGridView1.DataSource = null;//会将DataGridView的列也删掉 //2.this.dataGridView1.Columns.Clear( ...

  2. C# DataGridView控件清空数据完美解决方法

    C# DataGridView控件绑定数据后清空数据在清除DataGridview的数据时: 1.DataSource为NULL(DataGridView.DataSource= null;)这样会将 ...

  3. 转:C# DataGridView控件清空数据出错解决方法

    C# DataGridView控件绑定数据后清空数据在清除DataGridview的数据时: 1.DataSource为NULL(DataGridView.DataSource= null;)这样会将 ...

  4. javascript之JSON小案例,实现添加数据与清楚数据

    对json应用给出一个小案例,加深一些理解: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" & ...

  5. Eclipse中java向数据库中添加数据,更新数据,删除数据

    前面详细写过如何连接数据库的具体操作,下面介绍向数据库中添加数据. 注意事项:如果参考下面代码,需要 改包名,数据库名,数据库账号,密码,和数据表(数据表里面的信息) package com.ning ...

  6. Jmeter—4 添加断言 判断响应数据是否符合预期

    发出请求之后,通过添加断言可以判断响应数据是否是我们的预期结果. 1 在Jmeter中发送一个登录的http请求(参数故意输入错误).结果肯定是登陆失败啦. 但结果树中http请求的图标显示‘绿色’表 ...

  7. Oracle session inactive状态临时表数据未清空问题

    问题描述:Oracle数据库,java代码使用某数据库实例,获取connection并在使用结束关闭,而session未销毁,而是状态变为inactive从而导致临时表数据未清空. Oracle临时表 ...

  8. 删除数据表和清空数据表的内容(保存表结构)的SHELL脚本

    A,删除指定数据库的所有数据表 #!/bin/bash # 删除mysql中所有表 # 示例: # Usage: ./script user password dbnane # Usage: ./sc ...

  9. 金蝶KIS专业版替换SXS.dll 遭后门清空数据被修改为【恢复数据联系QQ 735330197,2251434429】解决方法 修复工具。

    金蝶KIS专业版 替换SXS.dll 遭后门清空数据(凭证被改为:恢复数据联系QQ 735330197,2251434429)恢复解决方法. [客户名称]:山东青岛福隆发纺织品有限公司 [软件名称]: ...

随机推荐

  1. 10.shard、replica机制及单node下创建index

    主要知识点     1.shard&replica机制梳理 2.单node环境下创建index的情况     1.shard&replica机制再次梳理     (1)index包含多 ...

  2. 【4】Django 创建第一个模块应用

    大成若缺,其用不弊.大盈若冲,其用不穷.大直若屈.大巧若拙.大辩若讷.静胜躁,寒胜热.清静为天下正 --老子<道德经> 本章内容 创建应用(app) 开发第一个视图(View) URL访问 ...

  3. 松哥整理了 15 道 Spring Boot 高频面试题,看完当面霸

    什么是面霸?就是在面试中,神挡杀神佛挡杀佛,见招拆招,面到面试官自惭形秽自叹不如!松哥希望本文能成为你面霸路上的垫脚石! 做 Java 开发,没有人敢小觑 Spring Boot 的重要性,现在出去面 ...

  4. UOJ #131 BZOJ 4199 luogu P2178【NOI2015】品酒大会 (后缀自动机、树形DP)

    水是水,但是写出了不少问题,因此写一发博客. https://www.luogu.org/problemnew/show/P2178 https://www.lydsy.com/JudgeOnline ...

  5. Java开发编码规范

    第一章 代码开发规范及其指南 一.1 目的 定义这个规范的目的是让项目中所有的文档都看起来像一个人写的,增加可读性,减少项目组中因为换人而带来的损失.(这些规范并不是一定要绝对遵守,但是一定要让程序有 ...

  6. 【ACM】nyoj_2_括号配对问题_201308091548

    括号配对问题时间限制:3000 ms  |  内存限制:65535 KB 难度:3描述 现在,有一行括号序列,请你检查这行括号是否配对. 输入 第一行输入一个数N(0<N<=100),表示 ...

  7. asp.net常用容器

    autofac就是ioc的第三方的IOC容器 unity也是IOC容器 掌握这两个容器就可以了,非常简单

  8. EF--code first数据迁移命令

    原文推荐!点我点我! 添加Migrations文件夹,并生成类文件Configuration.cs PM> Enable-Migrations -EnableAutomaticMigration ...

  9. CODEVS——T 1297 硬币

    http://www.codevs.cn/problem/1297/  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解       题目描述 Descrip ...

  10. javascript学习笔记(一)-廖雪峰教程

    一. 基础 1.for in,for of和forEach 遍历的是对象的属性,因为数组也是对象,其内部的元素的索引就是其属性值.用该方式遍历数组就是获取了数组中的每一个元素的索引值(从0開始). 而 ...