如何在dataGridView中绑定各个列 [英] how to bind individual columns in dataGridView

查看:117
本文介绍了如何在dataGridView中绑定各个列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有dataGridView的winForm,它具有5个文本框列和1个组合框列.我已经成功地将组合框绑定到我的bindingSource对象,现在我想将其他两列绑定到我的bindingSource对象.

我该如何绑定单个列?我似乎无法弄清楚如何将单个文本框列绑定到我的bindingSource.

I have a winForm with a dataGridView that has 5 textbox columns and one combobox column. I''ve successfully binded the combobox to my bindingSource object, now I''d like to bind two other columns to my bindingSource object.

How do I go about binding individual columns? I can''t seem to figure how to bind individual textbox columns to my bindingSource.

推荐答案

DataSource DataGridView
的属性 和DataGridViewColumn DataPropertyName ,如此处所述
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcolumn.datapropertyname.aspx [ ^ ]
可用于此目的.

在设置DataGridView DataSource属性之前,应将AutoGenerateColumns 属性设置为false,以避免DataGridView 自动填充Columns .
DataSource property of DataGridView
and DataPropertyName of DataGridViewColumn as explained here
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcolumn.datapropertyname.aspx[^]
can be used for this purpose.

Before setting the DataSource property of DataGridView the AutoGenerateColumns property is to be set to false to avoid the DataGridView populating the Columns automatically.
dataGridView1.AutoGenerateColumns = false;


这篇关于如何在dataGridView中绑定各个列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆