Results 1 to 6 of 6

Thread: Dynamic DGV

  1. #1

    Thread Starter
    Addicted Member Alexandru_mbm's Avatar
    Join Date
    Jul 2007
    Location
    VBForums.com
    Posts
    157

    Resolved Dynamic DGV

    Hello again...

    I have a DGV populated thru a BindingSource that shows me some values from the database. In the same DGV i have an empty Column...

    How can i populate the second column for example; Column 2 = Column 1 + 10 ?

    Thanks in advice!
    I'm still learning VB.NET
    Sorry for my bad english
    Thanks for your help

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

    Re: Dynamic DGV

    I assume that the BindingSource is bound to a DataTable. Is that empty column in the DataTable or is it an unbound column in the grid only? This would be much easier if it was in the DataTable.
    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
    Addicted Member Alexandru_mbm's Avatar
    Join Date
    Jul 2007
    Location
    VBForums.com
    Posts
    157

    Re: Dynamic DGV

    The second column i want to be unbounded because is just for information propouse only. It will not be used to be stored into a database or somethink like this...
    I'm still learning VB.NET
    Sorry for my bad english
    Thanks for your help

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

    Re: Dynamic DGV

    Even if it has nothing to do with the database you can still add the column to the DataTable. It's just that doing so makes everything much easier because the DataColumn can handle everything for you. Otherwise you'd have to handle events and perform the calculation yourself. It could look something like this:
    vb.net Code:
    1. Dim table As New DataTable
    2.  
    3. adapter.Fill(table)
    4. table.Columns.Add("Column2", GetType(Integer), "Column1 + 10")
    5. grid.DataSource = table
    That's all you have to do. The grid will create the display column automatically and the table will handle generating the values for the evaluated column. There's no issue when saving either because, unless you explicitly tell it to, there will be no attempt to save that column to the database.
    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

    Thread Starter
    Addicted Member Alexandru_mbm's Avatar
    Join Date
    Jul 2007
    Location
    VBForums.com
    Posts
    157

    Re: Dynamic DGV

    Code:
    Unable to cast object of type 'System.Data.DataTable' to type 'oft_produseDataTable'.
    ???
    I'm still learning VB.NET
    Sorry for my bad english
    Thanks for your help

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

    Re: Dynamic DGV

    So you're using a typed DataSet, with typed DataTables and TableAdapters instead of DataAdapters. You have to create an instance of your typed oft_produseDataTable class instead of the standard DataTable class. I've never tried but I don't see why you wouldn't be able to add a new column to it still. It is derived from DataTable so it's still got all the members a DataTable has.
    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