|
-
May 18th, 2013, 03:02 AM
#1
Thread Starter
New Member
grid views
Hi,
I have a grid view with 5 columns and I am assigning a data source to it at run time. The values of the data source are however being appended to the gridview i.e. new columns are being added instead of the values starting from the second column (the first column has check boxes).
Please can somebody help to resolve this problem.
Thanks
-
May 18th, 2013, 03:26 AM
#2
Re: grid views
First of all, what do you mean by "a grid view". Is this an ASP.NET application and you have a GridView control, or is it a Windows Forms app with a DataGridView, or maybe something else? Please be clear and use the correct names for things because vague approximations are a great way to cause confusion. If we make an incorrect assumption then it's a big waste of everyone's time.
-
May 18th, 2013, 03:58 AM
#3
Thread Starter
New Member
Re: grid views
 Originally Posted by jmcilhinney
First of all, what do you mean by "a grid view". Is this an ASP.NET application and you have a GridView control, or is it a Windows Forms app with a DataGridView, or maybe something else? Please be clear and use the correct names for things because vague approximations are a great way to cause confusion. If we make an incorrect assumption then it's a big waste of everyone's time.
My apologies...it is a windows form app with a DataGridView. The DGV has 7 columns wherein the first column has checkboxes. I wanted the datasource to populate the remaining six columns but it is just appending the six columns after the first 7 columns of the DGV, inspite of setting auto generate column property to false. Now just to move forward till I find a better solution, I have hidden the 7 columns of the DGV, so that the datasource data is visible from the second column itself.
-
May 18th, 2013, 04:36 AM
#4
Re: grid views
If you create columns in the designer then you have to tell them what column/property of the data source to bind to. You do that by setting the DataPropertyName of each column.
-
May 18th, 2013, 04:42 AM
#5
Re: grid views
If you have load data say into a DataTable from a database or perhaps reading data from a local xml file then after loading the data into the DataTable add a new DataColumn to the DataTable, set the ordinal position of the new column to 0 then set the value to each row for the Boolean column to False. Now when you assign the DataTable as the DataSource for the DataGridView (with no pre-defined columns) you will get the CheckBox first then the other fields in suit.
Example where I am loading data from an xml file into a Datatable in a DataSet. I don't have VS2008 installed so not sure if the add new data column will work as I did it in VS2010, adjust as needed.
Code:
Dim ds As New DataSet
ds.ReadXml(FileName)
Dim CheckCol As New DataColumn With {.ColumnName = "Process", .DataType = GetType(Boolean)}
ds.Tables(0).Columns.Add(CheckCol)
CheckCol.SetOrdinal(0)
For Each row As DataRow In ds.Tables(0).Rows
row.SetField(Of Boolean)("Process", False)
Next
DataGridView1.DataSource = ds.Tables(0)
-
May 18th, 2013, 05:04 AM
#6
Thread Starter
New Member
Re: grid views
 Originally Posted by jmcilhinney
If you create columns in the designer then you have to tell them what column/property of the data source to bind to. You do that by setting the DataPropertyName of each column.
thanks a lot, your suggestion worked.
-
May 18th, 2013, 07:41 AM
#7
Junior Member
Re: grid views
I think you are talking about the Gridview that is used in Asp.Net applications.
-
May 18th, 2013, 09:52 AM
#8
Re: grid views
 Originally Posted by annaharris
I think you are talking about the Gridview that is used in Asp.Net applications.
Given that I specifically asked whether it was a WinForms DataGridView or a WebForms GridView and the OP specifically replied that it was the former, plus the fact that my advice would not work with a WebForms GridView, I think that you're wrong. I'm not a moderator at this forum but that post was just as helpful as those you've made a the two that I am, i.e. not at all.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|