C#WinForm datagirdview的datapropertyname给每列绑定数据

1 UI

2

3

4 代码

 1 using System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Data;
 5 using System.Drawing;
 6 using System.Linq;
 7 using System.Text;
 8 using System.Threading.Tasks;
 9 using System.Windows.Forms;
10
11 namespace WindowsFormsApplication1
12 {
13     public partial class Form1 : Form
14     {
15         public Form1()
16         {
17             InitializeComponent();
18         }
19
20         private void Form1_Load(object sender, EventArgs e)
21         {
22
23             List<Test> datas = new List<Test>();
24             datas.Add(new Test() { Name = "乾", Age = "1" });
25
26             //绑定数据
27             dataGridView1.DataSource = datas;
28
29         }
30         class Test
31         {
32             private string _name;
33             private string _age;
34
35             public string Name
36             {
37                 get
38                 {
39                     return _name;
40                 }
41
42                 set
43                 {
44                     _name = value;
45                 }
46             }
47
48             public string Age
49             {
50                 get
51                 {
52                     return _age;
53                 }
54
55                 set
56                 {
57                     _age = value;
58                 }
59             }
60         }
61     }
62 }

5 效果

时间: 2024-08-01 10:32:34

C#WinForm datagirdview的datapropertyname给每列绑定数据的相关文章

C#.Net 给DataGridView列绑定数据和显示列名的方法

选择DataGridView控件,在属性中选择Colums属性项点击,编辑DataGridView控件的列,可以通过列编辑器添加多个列项,其中列属性的中HeadText是对外显示的,即向用户呈现的,Name是用于命名列对象的,而DataPropertyName是用于指定你将数据源的那一列绑定到该列上的,就是这个列属性可以DataGridView中的列绑定指定的数据,具体只需要将DataPropertyName列属性指定为数据源的某个列名即可,例如:数据源中一列为“UserName”,则将Data

GridView等表格模板列绑定数据的方法

//绑定GridView每一行中的CheckBoxList protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { CheckBoxList cbl = (CheckBoxList)e.Row.FindControl("ckbCheckBox"); if (cbl != null) {

C# 控制datagridview的combox属性的列绑定数据

//datagridvie列绑定list的数据 List<User> listChange = GetChange();//查询数据库内容,保存到list this.datagridview1.AutoGenerateColumns = false;//禁止生成不需要的列 this.datagridview1.DataSource = listChange;//list的内容绑定到datagridview Gender.DataSource = listChange;//list的内容绑定到d

Datagridview列绑定数据

属性最下面的Column项: 把每一列的字段绑定,更改显示的标题. 数据绑定代码: 1 string sql = "select IncomeExpendTypeID , TypeName , IncomeExpendTypeName , Remark from IncomeExpendType"; 2 3 this.dataGridView1.DataSource = shl.ExecuteDataTable(sql, CommandType.Text); *当然其中使用了SQLHe

C#WinForm 显示选中行的第一列单元格的内容,datagridview控件

1 UI 2 code 1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Threading.Tasks; 9 using System.Windows.Forms; 10 11

[WinForm] DataGridView绑定DataTable,ComboBox列绑定Dictionary

一  需求介绍 一般像枚举类型的数据,我们在数据库里存储着诸如(1.2.3.4-)或者("001"."002"."003"-)此类,但是界面上我们想要显示的是具体的文本内容,以便用户理解使用.所以在从数据库中加载出来的数据DataTable绑定到DataGridView上时,就需要其中一些枚举列采用下拉框,并绑定对应的枚举数据源. 二  具体实现 首先,如果 DataGridView 的 AutoGenerateColumns 为 true 时,

基于py3和pymysql的数据库查询,查询某几列的数据

#python3 #xiaodeng #基于py3和pymysql的数据库查询,查询某几列的数据 import pymysql conn=pymysql.connect(....) cur=conn.cursor() cur.execute("select name,age from nlist") data=cur.fethall() for name,age in data: print name,age conn.close() cur.close()

如何用perl将表格中不同列的数据进行拼凑,然后将拼凑后的数据用“|”连接在一起

最近写了一个perl脚本,实现的功能是将表格中其中两列的数据进行拼凑,然后将拼凑后的数据用“|”连接在一起. 表格内容如下: 员工号码 员工姓名 职位 入职日期 1001 张三 销售 1980/12/17 0:00:00 1002 李四 财务 1981/02/20 0:00:00 1003 王五 经理 1981/02/22 0:00:00 1004 陈二 会计 1981/04/02 0:00:00 要求如下: 将员工姓名和入职日期用键值对的形式拼凑在一起,然后将拼凑后的数据用“|”连接在一起.

WPF DataGrid的DataGridCheckBoxColumn列前台勾选后对应的绑定数据并未更新

WPF用的时间也不短了,还是遇到一些低级问题,好惭愧. 问题是这样的,WPF的DataGrid中,DataGridCheckBoxColumn列绑定了数据源中的一个boo类型的字段,模式为TwoWay,但界面中勾选后,数据源中的对应字段内容并未更新, 这样就好了 Binding="{Binding IsEmergency,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" 记录一下答案使这里找到的,微软官方论坛好强大. https://s