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

查看:44
本文介绍了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.

推荐答案

http://hodentekhelp.blogspot.com/2008/07/how-to-bind-dataset-to-datagridview.html

这应该有助于您的数据绑定

This should help with your databinding

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcheckboxcolumn.aspx

查看复选框列

这里是一些示例代码

        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天全站免登陆