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.
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.
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.
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];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With