c# datagridview绑定数据源(BindingList<class>)中的现象 待查
现象1:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms; namespace datagridview
{
public partial class Form1 : Form
{
public Int32 count = 0;
public string str = "test!";
BindingList<Item> items = new BindingList<Item>(); public Form1()
{
InitializeComponent(); //禁止自动创建列
this.dataGridView1.AutoGenerateColumns = false; //将左边的一栏去掉
this.dataGridView1.RowHeadersVisible = false; //允许用户交换列
this.dataGridView1.AllowUserToOrderColumns = true; this.dataGridView1.DataSource = items; //创建“序号”列
DataGridViewTextBoxColumn serial = new DataGridViewTextBoxColumn();
serial.HeaderText = "序号";
serial.DataPropertyName = "Serial";
this.dataGridView1.Columns.Add(serial); //创建“文本”列
DataGridViewTextBoxColumn text = new DataGridViewTextBoxColumn();
text.HeaderText = "文本";
text.DataPropertyName = "Text";
this.dataGridView1.Columns.Add(text); } private void button1_Click(object sender, EventArgs e)
{
} private void button2_Click(object sender, EventArgs e)
{
items.Add(new Item(str, count++));
//items.Add(new Item(0) { Text = str, Serial = count++ }); //有时候使用DataGridView难免会在最后插入一条数据,如果插入的数据超过滚动条显示的行数,
//那么默认情况下不会显示到最后一行。增加以下代码一直将滚动条拉倒最低。
this.dataGridView1.FirstDisplayedScrollingRowIndex = this.dataGridView1.Rows.Count - 1;
}
} class Item
{
private string _text;
private int _serial; public string Text
{
get { return _text; }
} public int Serial
{
get { return _serial; }
} public Item(string text, int serial)
{
this._text = text;
this._serial = serial;
} //public string Text { get; set; } //public int Serial { get; set; } //public Item(int serial)
//{
// int a = 0;
//}
}
}
运行结果:

当在Item类中增加默认构造函数后:
class Item
{
private string _text;
private int _serial; public string Text
{
get { return _text; }
} public int Serial
{
get { return _serial; }
} public Item(string text, int serial)
{
this._text = text;
this._serial = serial;
} public Item()
{
int a = 0;
}
运行结果:

显示最后一栏空白,原因未知待查!
c# datagridview绑定数据源(BindingList<class>)中的现象 待查的更多相关文章
- C# DataGridView绑定数据源的几种常见方式
开始以前,先认识一下WinForm控件数据绑定的两种形式,简单数据绑定和复杂数据绑定. 1. 简单的数据绑定 例1 using (SqlConnection conn = new SqlConnect ...
- DataGridView绑定数据源
给DataGridView绑定数据源比較简单,方法主要有两种: 1.直接在控件属性中绑定数据源,这样的方法最简单,但它是直接连接数据库的,这样就和传DataTable的后果差点儿相同了,所以还是尽量避 ...
- DataGridView绑定数据源的几种方式
使用DataGridView控件,可以显示和编辑来自多种不同类型的数据源的表格数据. 将数据绑定到DataGridView控件非常简单和直观,在大多数情况下,只需设置DataSource属性即可.在绑 ...
- 章鱼哥出品—VB.NET DataGridView绑定数据源 "与货币管理器的位置关联的行不能设置为不可见" 问题的解决
DtaGridView绑定数据源后.假设想让数据条件显示的话,直接使用 My_Row.Visible = False就会出错.错误类型是 "与货币管理器的位置关联的行不能设置为不可见&qu ...
- DataGridView绑定数据源后添加行
本文链接:https://blog.csdn.net/u012386475/article/details/88639799 在已经绑定数据源时,无法以Add的方式方式添加行,会报错 解决方法一: D ...
- 【转】DataGridView绑定数据源的几种方式
第一种:DataSet ds=new DataSet (); this.dataGridView1.DataSource=ds.Table[0]; 第二种:DataTable dt=new DataT ...
- C# 关于DataGridView 绑定数据源时列名窜位置 的处理
只需要写一句话:dataGridView1.AutoGenerateColumns = false; 代码提示中的解释:获取或设置一个值,该值指示在设置System.Windows.Forms.Dat ...
- C# DataGridView绑定数据源
第一种: DataSet ds=new DataSet (); ]; 第二种: DataTable dt=new DataTable(); this.dataGridView1.DataSource= ...
- winfrom中DataGridView绑定数据控件中DataGridViewCheckBoxColumn怎么选中
; i < this.dataGridView1.Rows.Count; i++) { this.dataGridView1.Rows[i].Cells["CheckBoxCulums ...
随机推荐
- 配置使用 git 秘钥连接 GitHub
配置使用 git 秘钥连接 GitHub 在Linux下部署Git环境 1.安装Git. 使用命令安装 git . sudo apt-get install git 2.创建一个 Github 账号 ...
- node.js 初学(一)—— http fs 服务器/文件/post get
node.js 初学 —— http fs 服务器/文件/post get 这个世界,从来不会给失败者颁奖! 了解 node.js (开源) node.js 是用来做后台开发的,但是现在大部分前端人员 ...
- k8s device plugin
基本概念入门: Device Manager Proposal Device plugin offical Doc(中文) device-plugins offical Doc(En) Go thro ...
- day28 网络编程
网络编程 什么是网络编程? 编写基于网络的应用程序的过程称之为网络编程 一.CS构架 C/S构架 服务器和客户端之间用网线连接 提供数据的计算机称为服务器,访问数据的计算机称为客户端 二.网络通讯的基 ...
- shell编程(三)之条件判断(if语句)
练习:写一个脚本判断当前系统上是否有用户的默认shell为bash: 如果有,就显示有多少个这类用户:否则,就显示没有这类用户: #!/bin/bash # grep '\<bash$' /et ...
- Git 配置命令设置
目录 查看配置文件路径: 查看其他配置命令: 修改配置文件默认路径: 查看配置文件路径: 查看系统级别配置: git config -e –-system D:/Program Files/Git/m ...
- Baseline
Baseline Baselines an existing database, excluding all migrations upto and including baselineVersion ...
- javbus爬虫-老司机你值得拥有
# 起因 有个朋友叫我帮忙写个爬虫,爬取javbus5上面所有的详情页链接,也就是所有的https://www.javbus5.com/SRS-055这种链接, 我一看,嘿呀,这是司机的活儿啊,我绝对 ...
- 【问题解决:死锁】Lock wait timeout exceeded; try restarting transaction的问题
执行数据删除操作时一直超时并弹出Lock wait timeout exceeded; try restarting transaction错误 解决办法 1.先查看数据库的事务隔离级别 select ...
- 【示例】Spring Quartz入门
JAVA 针对定时任务,有 Timer,Scheduler, Quartz 等几种实现方式,其中最常用的应该就是 Quartz 了. 一. Quartz的基本概念 在开始之前,我们必须了解以下的几个基 ...