需求

软件界面需要使用表格,对数据进行显示、交互,这是一个非常通用的需求。

实现方法

DataGridView介绍

参考 https://docs.microsoft.com/en-us/dotnet/desktop/winforms/controls/basic-formatting-and-styling-in-the-windows-forms-datagridview-control?view=netframeworkdesktop-4.8

微软的文档介绍的非常清楚,这个winform的控件提供了客制化的图表显示功能。

The DataGridView control provides a customizable table for displaying data. The DataGridView class allows customization of cells, rows, columns, and borders through the use of properties such as DefaultCellStyle, ColumnHeadersDefaultCellStyle, CellBorderStyle, and GridColor. For more information, see Basic Formatting and Styling in the Windows Forms DataGridView Control.

You can use a DataGridView control to display data with or without an underlying data source. Without specifying a data source, you can create columns and rows that contain data and add them directly to the DataGridView using the Rows and Columns properties. You can also use the Rows collection to access DataGridViewRow objects and the DataGridViewRow.Cells property to read or write cell values directly. The Item[] indexer also provides direct access to cells.

As an alternative to populating the control manually, you can set the DataSource and DataMember properties to bind the DataGridView to a data source and automatically populate it with data. For more information, see Displaying Data in the Windows Forms DataGridView Control.

When working with very large amounts of data, you can set the VirtualMode property to true to display a subset of the available data. Virtual mode requires the implementation of a data cache from which the DataGridView control is populated. For more information, see Data Display Modes in the Windows Forms DataGridView Control.

For additional information about the features available in the DataGridView control, see DataGridView Control. The following table provides direct links to common tasks.

简单的使用

对于不算复杂的应用,我们只需要为DataGridView指定数据源即可,我们的典型用法是,创建一个list,然后将该list作为控件的数据源。

声明数据源,直接用List的方式,简化设计

///



/// AI EEPROM Information Class,用于声明一个数据行

///

public class AIEEPROMInformation

{

private bool calibration;

private double aigainValue;

private double aioffsetValue;

private double range;

private AICoupling coupling;

private AIImpedance impedance;

private int channel;

        public int Channel
{
get
{
return channel;
}
set
{
channel = value;
}
} public double Range
{
get
{
return range;
} set
{
range = value;
}
} public AICoupling Coupling
{
get
{
return coupling;
} set
{
coupling = value;
}
} public AIImpedance Impedance
{
get
{
return impedance;
} set
{
impedance = value;
}
} public bool Calibration
{
get
{
return calibration;
} set
{
calibration = value;
}
}
public double AigainValue
{
get
{
return aigainValue;
} set
{
aigainValue = value;
}
} public double AioffsetValue
{
get
{
return aioffsetValue;
}
set
{
aioffsetValue = value;
}
}
}

用于声明一个基于AIEEPROMInformation行的数据源

BindingList aiEEPROMList;

    aiEEPROMList = new BindingList<AIEEPROMInformation>();

绑定数据源

dataGridView_AIRead.DataSource = aiEEPROMList1;//获取数据源

更新数据源即可完自动成显示

dataGridView_AIRead.Update();

使用代码绑定 DataGridView 控件用于程序界面显示表格的更多相关文章

  1. ASP通过代码绑定Gridview控件

    using System.Configuration;using System.Data.OleDb;using System.Data; public partial class datafilm ...

  2. Visual Basic 2012 借助DataGridView控件将SQL server2012 数据导入到Excel 2010

    摘  要: SQL Server 2012 数据和Excel 2010之间的连接和数据的传输,本篇文章主要针对的是SQL Server 2012 数据导入到Excel 2010文件中.Excel软件对 ...

  3. C#实现WinForm下DataGridView控件的拷贝和粘贴

    DataGridView控件应该是数据库应用系统最常用的控件之一,其方便性不言而喻的.往往用户在使用过程中会提出"从DataGridView空间 中拷贝数据或是向某个DataGridView ...

  4. DataGridView控件-学习笔记总结

    1.GridColor属性用来获取或设置网格线的颜色 dataGridView1.GridColor=Color.Blue; 2.设置宽度 .高度 dataGridView1.Columns[].Wi ...

  5. 最佳实践扩展Windows窗体DataGridView控件 .net 4.5 附示例代码

    Windows窗体DataGridView控件的性能调优.net 4.5   在处理大量数据时, DataGridView 控制可以消耗大量的内存开销,除非你仔细地使用它. 在客户有限的内存,你可以避 ...

  6. [置顶] DataGridView控件---绑定数据方法

             DataGridView控件是在windows应用程中显示数据最好的方式,它只需要几行简短的代码就可以把数据显示给用户,同时又支持增.删.改操作.今天将自己总结的增加数据的方法总结分 ...

  7. DataGridView:DataGridView控件清空绑定的数据

    使用DataGridView控件绑定数据后有时需要清空绑定的数据,在清除DataGridView绑定的数据时: 1.设置DataSource为null this.dgvDemo.DataSource ...

  8. DataGridView控件绑定数据源

    前言: 近期听说DataGridView控件能直接绑定数据源.而不用穿越这层那层的忍辱负重.获取数据.真是高兴的屁颠屁颠的.后来一想二狗肯定不会弄.特意写了一个笨蛋版的教程--也算记录生活.欢度端午了 ...

  9. DataGridVIew控件绑定数据之后的,增、插、删操作

    最开始没有绑定数据,很快就实现了增.插.删操作,可是绑定数据之后,进行这些操作就会报错. 网上对这方面的资料比较少,自己摸索着找到了解决方法,也就是直接对绑定的数据进行操作,这里以DataTable为 ...

随机推荐

  1. Java的jar包构建成docker镜像并运行

    结构如下 把jar和Dockerfile放到一个文件,不在一个文件下会报错文件找不到 创建一个构建文件 buildimage.sh vi /home/hanby/buildimage.sh echo ...

  2. Apache Shiro反序列化远程代码执行复现

    最近也是看shiro漏洞比较多,所以自己也在本地复现了一下,拿出来与大家一起分享 0x00 关于Apache Shiro Apache shiro是一个Java安全框架,提供了认证.授权.加密和会话管 ...

  3. 《Go组件设计与实现》-netpoll的总结

    主要针对字节跳动的netpoll网络库进行总结.netpoll网络库相比于go本身的net标准库更适合高并发场景. 基础知识 netpoll与go.net库一样使用epoll这种IO多路复用机制处理网 ...

  4. 《剑指offer》面试题67. 把字符串转换成整数

    问题描述 写一个函数 StrToInt,实现把字符串转换成整数这个功能.不能使用 atoi 或者其他类似的库函数.   首先,该函数会根据需要丢弃无用的开头空格字符,直到寻找到第一个非空格的字符为止. ...

  5. 【白话科普】《逆局》最终 boss 隐藏自己的方式是?

    二狗子最近在看一个很火的电视剧<逆局>.作为一部悬疑犯罪剧,剧中多个案件交织并进,悬念和转折拉满,让狗子看的直呼过瘾.特别最后一幕,杨副座和主角团同时对 U 盘中的关键证据"器官 ...

  6. 【刷题-LeetCode】221. Maximal Square

    Maximal Square Given a 2D binary matrix filled with 0's and 1's, find the largest square containing ...

  7. 🏆【Alibaba中间件技术系列】「RocketMQ技术专题」Broker服务端自动创建topic的原理分析和问题要点指南

    前提背景 使用RocketMQ进行发消息时,一般我们是必须要指定topic,此外topic必须要提前建立,但是topic的创建(自动或者手动方式)的设置有一个开关autoCreateTopicEnab ...

  8. Ajax_GET的一个基本用法

    Ajax_GET的一个基本用法 首先先创建一个Server.js文件 ​//1.引入express// const { response } = require('express');const ex ...

  9. AOP-底层原理(JDK动态代理实现)

    AOP(JDK动态代理) 1,使用JDK动态代理,使用Proxy类里面的方法创建代理对象 (1)调用 newProxyInstance 方法 方法有三个参数 第一参数,类加载器 第二参数,增强方法所在 ...

  10. 用 CSS 让你的文字更有文艺范

    透明文字,模糊文字,镂空文字,渐变文字,图片背景文字,用 CSS 让你的文字也有 freestyle- 前言 我们做页面涉及字体的时候,最多就是换个 color 换个 font-family,总是觉得 ...