Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS2010 - WinForms - DataGridView - Binding to DataSet

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;

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

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

like image 904
kalls Avatar asked Nov 16 '11 16:11

kalls


People also ask

How to use DataGridView in c# Windows Form?

Drag and drop DataGridView control from toolbox to form window. Figure 2. Now choose a data source by right clicking on the DataGridView and then click on Add Project Data Source. We will be adding a new data source to the project right now.

What is DataGridView data binding?

The DataGridView can display data in Bound mode and unbound mode and Virtual mode. The easiest way to get started using the DataGridView control is to use it in basic data binding scenarios. The DataGridView control can display rows of data from a data source.


1 Answers

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

take a look at that for the checkbox column

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];     
like image 77
BDubCook Avatar answered Nov 10 '22 00:11

BDubCook