Results 1 to 8 of 8

Thread: grid views

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2013
    Posts
    15

    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

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2013
    Posts
    15

    Re: grid views

    Quote Originally Posted by jmcilhinney View Post
    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.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,713

    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)

  6. #6

    Thread Starter
    New Member
    Join Date
    May 2013
    Posts
    15

    Re: grid views

    Quote Originally Posted by jmcilhinney View Post
    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.

  7. #7
    Junior Member
    Join Date
    Apr 2013
    Posts
    17

    Re: grid views

    I think you are talking about the Gridview that is used in Asp.Net applications.

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: grid views

    Quote Originally Posted by annaharris View Post
    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width