Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Reusable DataGridView and TableAdapter components in Lookup Tables?

Reusable DataGridView and TableAdapter components in Lookup Tables?

Scheduled Pinned Locked Moved Database
csharpcssdatabasesql-servervisual-studio
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bert Edens
    wrote on last edited by
    #1

    Greetings, all... I'm using Visual Studio 2008 Express with C# and SQL Server 2008 backend. I'm wanting to design a lookup table form where the user can select the table from a list of items on the left (probably a TreeView with a node for each entry), then have the grid on the right reflect the contents of that table (Users, Config settings, Security, etc.). But I don't have to have a table adapter for each table that could be on the form and would like to re-use the component by setting the properties on the fly. Has anyone done this before? As a corrolary to this, if the user double-clicks on an entry in the grid, I would like to pop-up a form to allow the user to edit that entry. Again, I would like to use a single form to do this, without having a different form and table adapter, binding source, etc., for each possible table. Has anyone done this before and can offer any suggestions? Or would the code to do it all run-time outweigh what it would take to just have separate table adapters and forms for each possible lookup table? Thanks in advance! - Bert

    M 1 Reply Last reply
    0
    • B Bert Edens

      Greetings, all... I'm using Visual Studio 2008 Express with C# and SQL Server 2008 backend. I'm wanting to design a lookup table form where the user can select the table from a list of items on the left (probably a TreeView with a node for each entry), then have the grid on the right reflect the contents of that table (Users, Config settings, Security, etc.). But I don't have to have a table adapter for each table that could be on the form and would like to re-use the component by setting the properties on the fly. Has anyone done this before? As a corrolary to this, if the user double-clicks on an entry in the grid, I would like to pop-up a form to allow the user to edit that entry. Again, I would like to use a single form to do this, without having a different form and table adapter, binding source, etc., for each possible table. Has anyone done this before and can offer any suggestions? Or would the code to do it all run-time outweigh what it would take to just have separate table adapters and forms for each possible lookup table? Thanks in advance! - Bert

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      This belongs in the design and architecture forum, certainly not the database forum, this has absolutely nothing to do with database. Having said that, this is our standard design. First you need to chuck out the tableadaptor concept, you are using the MS widget/wizard crap things. Do some research into Data Access Layer, it will change the way you manage your data. I have a utility that takes a datatable and binds it to a datagridview, formats the DGV and the various columns based on the data types of the datatable. I have a giant switch statement that reacts to the node click event, gets the currentview (enum of all the tables to be displayed) from the node and decides what object to get a datatable from. The datatable is then passed to the DGV loader utility. Then on the double click event of the DGV I already know what the currentview is from the loader so I know what form to display based on the currentview. I have the ID of the record clicked on (first filed always has the ID and is not visible in the DGV) so I pass the ID to the form in the constructor and pop a dialog. The dialog gets the record (or an empty form for add) and saves the record back to the database. It returns a dialogresult to the main form. If the main form get an Ok result it reloads the datatable from the database and refreshes the DGV with the new record in it. As I said bog standard do it every day UI.

      Never underestimate the power of human stupidity RAH

      B 1 Reply Last reply
      0
      • M Mycroft Holmes

        This belongs in the design and architecture forum, certainly not the database forum, this has absolutely nothing to do with database. Having said that, this is our standard design. First you need to chuck out the tableadaptor concept, you are using the MS widget/wizard crap things. Do some research into Data Access Layer, it will change the way you manage your data. I have a utility that takes a datatable and binds it to a datagridview, formats the DGV and the various columns based on the data types of the datatable. I have a giant switch statement that reacts to the node click event, gets the currentview (enum of all the tables to be displayed) from the node and decides what object to get a datatable from. The datatable is then passed to the DGV loader utility. Then on the double click event of the DGV I already know what the currentview is from the loader so I know what form to display based on the currentview. I have the ID of the record clicked on (first filed always has the ID and is not visible in the DGV) so I pass the ID to the form in the constructor and pop a dialog. The dialog gets the record (or an empty form for add) and saves the record back to the database. It returns a dialogresult to the main form. If the main form get an Ok result it reloads the datatable from the database and refreshes the DGV with the new record in it. As I said bog standard do it every day UI.

        Never underestimate the power of human stupidity RAH

        B Offline
        B Offline
        Bert Edens
        wrote on last edited by
        #3

        Thank you for the quick reply. I apologize for the posting in the wrong location. This crossed over to several areas, so I wasn't sure where it fit best. I'm admittedly new to working with .NET and data access, having done most of my Windows coding in Delphi recently. Time to shift some paradigms, but that's just fine with me. :) Thanks again! - Bert

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups