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 ...
随机推荐
- 类中函数前、后、参数加const
1.参数加const:int fun(const int a) a在函数里不可被修改 2.函数前加const:const int* const fun() 这种一般是返回的指针或者是引用,加const ...
- Python3 tkinter基础 Frame bind 捕捉多键同时按
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Flutter学习指南:UI布局和控件
Flutter学习指南:UI布局和控件 - IT程序猿 https://www.itcodemonkey.com/article/11041.html
- linux基础之vim编辑器
vi : Visual Interface vim : VI Improved : VI的基础加上一些有用的插件 vim编辑器: 文本编辑器, 字处理器, 全屏编辑器, 模式化编辑器 vim的模式有三 ...
- R语言 apply,sapply,lapply,tapply,vapply, mapply的用法
apply() apply(m,dimcode,f,fargs) m 是一个矩阵. dimcode是维度编号,取1则为对行应用函数,取2则为对列运用函数. f是函数 fargs是f的可选参数集 > ...
- P4720 【模板】扩展卢卡斯
思路 扩展Lucas和Lucas定理其实没什么关系 我们要求的是这样的一个问题 \[ \left(\begin{matrix}n\\m\end{matrix}\right) mod\ P \] p不一 ...
- 深度学习课程笔记(十二) Matrix Capsule
深度学习课程笔记(十二) Matrix Capsule with EM Routing 2018-02-02 21:21:09 Paper: https://openreview.net/pdf ...
- Ubuntu yindaoxiufu 引导修复(Boot Repair)
Ubuntu yindaoxiufu 引导修复(Boot Repair) from: http://blog.csdn.net/piaocoder/article/details/50589667 ...
- Nand flash code
(1)流水灯 1>我们来看原理图 2>datasheet 3> ...
- 小文笔记 - phantomjs
小文笔记 - phantomjs 视频推荐: http://www.intalesson.com/compedium/phantom 2017-05-13 第一节:安装 Windows安装: 下载解压 ...