VS2010 - 的WinForms - DataGridView中 - 绑定到数据集 [英] VS2010 - WinForms - DataGridView - Binding to DataSet

查看:303
本文介绍了VS2010 - 的WinForms - DataGridView中 - 绑定到数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的WinForms,我有一个表格控件里面一个DataGridView。 我试图将其绑定到显示数据。

I am new to winforms and I have a datagridview inside a table control. I am trying to bind it to display data.

DataSet dataSet = new DataSet();
DataTable dataTable = dataSet.Tables.Add("Results");

dataTable.Columns.Add("ID");
dataTable.Columns.Add("Name");

dataTable.Rows.Add("1","Jack");
dataTable.Rows.Add("2","Donna");

dataGridView1.DataSource = dataSet;

我没有找到一个dataGridView1.DataBind?所以,我想知道我如何能做到这一点?

I don't find a dataGridView1.DataBind? So I am wondering how I can achieve this?

另外,我试图找出如何让DataGridView中为复选框的第一列。任何指针会有帮助。

Also, I'm trying to figure out how to have the first column of the DataGridView as a checkbox. any pointers would help.

推荐答案

<一个href="http://hodentekhelp.blogspot.com/2008/07/how-to-bind-dataset-to-datagridview.html">http://hodentekhelp.blogspot.com/2008/07/how-to-bind-dataset-to-datagridview.html

这应该帮助您的数据绑定

This should help with your databinding

<一个href="http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcheckboxcolumn.aspx">http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcheckboxcolumn.aspx

看一看,对于复选框列

下面是一些示例code

Here is some sample code

        DataSet ds = new DataSet();
        DataTable dt = new DataTable();
        dt.Columns.Add("Blah",typeof(bool));
        dt.Columns.Add("Blah2");
        ds.Tables.Add(dt);
        dataGridView1.DataSource = ds.Tables[0];     

这篇关于VS2010 - 的WinForms - DataGridView中 - 绑定到数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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