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. General Programming
  3. C#
  4. populate combobox by passing parameter to seperate class

populate combobox by passing parameter to seperate class

Scheduled Pinned Locked Moved C#
databasetutorial
5 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.
  • R Offline
    R Offline
    redspiderke
    wrote on last edited by
    #1

    Hi, I have +20 comboboxes in my windows app. and thought its best to have the code in a seperate class and than call that class and pass the parameters using a constructor... With this one function I hope to fill every combo box that i have in my application from a database table. But not sure how to get started with it. thanks Wouter

    N 1 Reply Last reply
    0
    • R redspiderke

      Hi, I have +20 comboboxes in my windows app. and thought its best to have the code in a seperate class and than call that class and pass the parameters using a constructor... With this one function I hope to fill every combo box that i have in my application from a database table. But not sure how to get started with it. thanks Wouter

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      First I'd say from a UI perspective 20+ comboboxes on a screen is probably not the best design. Think about breaking them up with tabs, or sub forms if it makes sense. What you can do is iterate through the controls collection to find each combobox and set the properties accordingly. Or you could set DataBinding between the comboboxes and your datatable


      I know the language. I've read a book. - _Madmatt

      R 1 Reply Last reply
      0
      • N Not Active

        First I'd say from a UI perspective 20+ comboboxes on a screen is probably not the best design. Think about breaking them up with tabs, or sub forms if it makes sense. What you can do is iterate through the controls collection to find each combobox and set the properties accordingly. Or you could set DataBinding between the comboboxes and your datatable


        I know the language. I've read a book. - _Madmatt

        R Offline
        R Offline
        redspiderke
        wrote on last edited by
        #3

        I have 14 forms and 20 combo's in total, So each form has max 2 comboboxes on it.

        N 1 Reply Last reply
        0
        • R redspiderke

          I have 14 forms and 20 combo's in total, So each form has max 2 comboboxes on it.

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          More reasonable then. DataBinding, IMO, would be the best approach in this case.


          I know the language. I've read a book. - _Madmatt

          R 1 Reply Last reply
          0
          • N Not Active

            More reasonable then. DataBinding, IMO, would be the best approach in this case.


            I know the language. I've read a book. - _Madmatt

            R Offline
            R Offline
            redspiderke
            wrote on last edited by
            #5

            Mark, Thanks, the answer was indeed easyer than the question, solved the problem ! In class "cls_role.cs":

            public DataTable GetRols()
            {
            DataTable DT = new DataTable();
            string Query = "GetRols";
            DT = _dbHelper.ExecuteDataTable(Query);
            return DT;
            }

            In Winform:

            private void GetRols()
            {
            Cls_Role Role = new Cls_Role();
            cmbRole.DataSource = Role.GetRols();
            cmbRole.DisplayMember = "Role_Name";
            cmbRole.ValueMember = "Role_ID";
            }

            I was thinking to complex :-D

            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