datagrid控件的作用简单点说就是将表格显示出来,用的多的是直接链接数据库文件,也可以自己见一个表格对象,链接到datagrid控件,下面是一个简单的例子

 1 //xinjiabiao
 2 DataTable dt = new DataTable();
 3             //新建列
 4             DataColumn col1 = new DataColumn("设备名", typeof(string));
 5             DataColumn col2 = new DataColumn("管理员", typeof(string));
 6             DataColumn col3 = new DataColumn("设备ID", typeof(string));
 7             DataColumn col4 = new DataColumn("所属权限", typeof(string));
 8             DataColumn col5 = new DataColumn("状态", typeof(string));
 9             DataColumn col6 = new DataColumn("购买时间", typeof(string));
10             DataColumn col7 = new DataColumn("最新维护时间", typeof(string));
11             DataColumn col8 = new DataColumn("设备管理员ID", typeof(string));
12             //添加列
13             dt.Columns.Add(col1);
14             dt.Columns.Add(col2);
15             dt.Columns.Add(col3);
16             dt.Columns.Add(col4);
17             dt.Columns.Add(col5);
18             dt.Columns.Add(col6);
19             dt.Columns.Add(col7);
20             dt.Columns.Add(col8);
21             //新建行
22             DataRow row1 = dt.NewRow();
23             //行赋值
24             row1["设备名"] = "打印机";
25             row1["管理员"] = "李居明";
26             row1["设备ID"] = "JFKSJFKSDFJK151";
27             row1["所属权限"] = "普通用户";
28             row1["状态"] = "在库";
29             row1["购买时间"] = "2012-03-20";
30             row1["最新维护时间"] = "2012-03-27";
31             row1["设备管理员ID"] = "无";
32             //添加行
33             dt.Rows.Add(row1);
34             //数据绑定
35             this.dataGrid1.DataSource = dt;
36             //设置属性
37             DataGridTableStyle tablestyle = new DataGridTableStyle();
38             this.dataGrid1.TableStyles.Add(tablestyle);
39             dataGrid1.TableStyles[0].GridColumnStyles[0].Width = 75;
40             dataGrid1.TableStyles[0].GridColumnStyles[1].Width = 75;
41             dataGrid1.TableStyles[0].GridColumnStyles[2].Width = 75;
42             dataGrid1.TableStyles[0].GridColumnStyles[3].Width = 75;
43             dataGrid1.TableStyles[0].GridColumnStyles[4].Width = 75;
44             dataGrid1.TableStyles[0].GridColumnStyles[5].Width = 120;
45             dataGrid1.TableStyles[0].GridColumnStyles[6].Width = 120;
46             dataGrid1.TableStyles[0].GridColumnStyles[6].Width = 120;

转自http://blog.sina.com.cn/s/blog_7e7b66a801012fuz.html

转载于:https://www.cnblogs.com/l289123557/p/3507330.html

C#中DataGrid控件的基本使用相关推荐

  1. VB.net数据库编程中DataGrid控件的使用技巧

    VB.net数据库编程中DataGrid控件的使用技巧 如何用同一个DataGrid显示不同的数据表:如何用DataGrid显示主表/明细表的内容:如何用DataGrid分页显示或编辑数据表的记录.这 ...

  2. WPF中DataGrid控件

    WPF中DataGrid控件的个别属性使用 //设置不可自动拉伸宽度dataGrid.CanUserResizeColumns = false;//第一列不可见dataGrid.HeadersVisi ...

  3. WPF 中DataGrid控件显示和设置数据

    一.基础知识 1.DataGrid控件:用来显示数据的控件,从对象集合中获取信息并在具有行和单元格的网格中显示信息.每行和单独的对象相对应,并且每列和对象的某个属性相对应. 2.在DataGrid 中 ...

  4. 有关WPF中DataGrid控件的基础应用总结

    基础说明 DataGrid是WPF提供的基础控件,它可以非常轻松的呈现出一张表格,本文章会按照从易到难的顺序依次将DataGrid的使用方法进行解说,除了MSDN上给出的最基本的例子之外,给出了三个比 ...

  5. EasyUI中datagrid控件的使用 设置多行表头(两行或多行)

    EasyUI中的datagrid控件十分强大,能生成各种复杂的报表,现在因为项目需要,需要生成一个表头两行的表,找了一些说明文档,以下用一个实例来说明一下: 第一种方法: 1 $('#divData' ...

  6. Asp.net中DataGrid控件的自定义分页

    使用实现起来虽然比较方便,但是效率不高,每次都需要读取所有页(整个记录集),而加载的只是其中一页,造成了资源的浪费,记录多又会使效率变得很低.下面通过DataGrid的自定义分页功能来减少资源使用和提 ...

  7. Silverlight 中datagrid控件-- 通过设置数据虚拟化加速显示

    定义依赖属性作为datagrid的数据源 protected static readonly DependencyProperty ViewLogsProperty = DependencyPrope ...

  8. asp.net中显示DataGrid控件列序号的几种方法

    在aps.net中多数据绑定的控件很多,论功能来说,应该属DataGrid最为齐全,但它没有提供现成的显示记录序号的功能,不过我们可以通过它所带的一些参数来间接得到序号,下面来看看怎样得到和显示序号值 ...

  9. WPF中如何将List<string>数据绑定到DataGrid控件中

    一,前端 <DataGrid x:Name="Onlinedatagrid" AutoGenerateColumns="True" HorizontalA ...

最新文章

  1. 面试官问我,Redis分布式锁如何续期?懵了。
  2. spring mvc 篇
  3. python验证中心极限定理_我竟然混进了Python高级圈子!
  4. python的工作方向-python工作方向,发展方向?
  5. jsp中jquery传值给Java_jsp中利用jquery+ajax在前后台之间传递json格式参数
  6. 扬州大学广陵学院计算机网络试卷,扬州大学广陵学院控制工程考试样卷B.doc
  7. 三维点集拟合:平面拟合、RANSAC、ICP算法
  8. Android之文件读写
  9. requests 分类多级页面_scrapy框架爬取多级页面
  10. php语法高亮编辑器,最新PHPCMS V9编辑器代码高亮显示亲测可用(提前格式化)
  11. flex3+blazeds+spring+hibernate整合小结
  12. Java——链表的增删查改
  13. html网页字段序号的样式,[网页设计]局部自定义li序号CSS样式的方法
  14. 人群与网络:搜索引擎广告位的定价
  15. html email template
  16. python下载整个网站_python 下载整个站点
  17. Python爬虫小项目——实现英语翻译功能(四)
  18. 80004005错误代码_关于访问共享时出现80004005错误
  19. [每天一个Linux小技巧] Goldendict 快速取词
  20. HCIE(第四天总结)---iStack、 CSS 、Eth-Trunk、 M-LAG

热门文章

  1. 合理设置apache参数
  2. 解决git本地仓库与远程仓库关联出现 failed to push some refs to git的问题
  3. python中实数怎么表示_如何用实数的模来计算pow()?
  4. Metasploit search命令使用技巧
  5. DNS枚举工具DNSenum
  6. 51单片机c语言测距,求助 关于C51单片机超声波测距 C语言程序设计 高手帮帮忙...
  7. java 循环读取文件_您如何用Java连续读取文件?
  8. ​Nature子刊 | 睡眠时型会影响人类大脑生理的认知功能
  9. ICLR要搞深度生成模型大讨论,Max Welling和AAAI百万美元大奖得主都来了,Bengio是组织者之一...
  10. 过半网友支持马斯克卖掉特斯拉10%股票,马斯克:会遵守投票结果