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
  1. Home
  2. General Programming
  3. Visual Basic
  4. filling 2 different combo boxes with info from same dataTable

filling 2 different combo boxes with info from same dataTable

Scheduled Pinned Locked Moved Visual Basic
helpquestion
14 Posts 3 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.
  • A AAGTHosting

    How do I make a copy? Do I just do another query or literally make a copy?

    C Offline
    C Offline
    Christian Graus
    wrote on last edited by
    #4

    you can use the CLone method to make a copy, I believe that makes a deep copy. Otherwise, you'd run your query again, but I'd try Clone() first.

    Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

    A 1 Reply Last reply
    0
    • C Christian Graus

      you can use the CLone method to make a copy, I believe that makes a deep copy. Otherwise, you'd run your query again, but I'd try Clone() first.

      Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      A Offline
      A Offline
      AAGTHosting
      wrote on last edited by
      #5

      I tried to run the query again and the program still freezes. When I ran the query again I also populated a completely different dataTable and it still didn't work. Then I tried to create a clone of the original dataTable and then the list box will populate and the program does not freeze, but the combo box does not populate.

      C 1 Reply Last reply
      0
      • A AAGTHosting

        I tried to run the query again and the program still freezes. When I ran the query again I also populated a completely different dataTable and it still didn't work. Then I tried to create a clone of the original dataTable and then the list box will populate and the program does not freeze, but the combo box does not populate.

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #6

        The app freezing is not a typical symptom of what goes wrong when you reuse a datasource. Usually changing one control just causes te other to change too. My guess is that you're not cloning it properly, and your source is empty. And, I would guess that you have code running on a selected index change which is being run by the databinding, and causing it ti freeze. If you break out or if you set breakpoints around the related code when you debug, wat happens ?

        Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

        A 1 Reply Last reply
        0
        • C Christian Graus

          The app freezing is not a typical symptom of what goes wrong when you reuse a datasource. Usually changing one control just causes te other to change too. My guess is that you're not cloning it properly, and your source is empty. And, I would guess that you have code running on a selected index change which is being run by the databinding, and causing it ti freeze. If you break out or if you set breakpoints around the related code when you debug, wat happens ?

          Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

          A Offline
          A Offline
          AAGTHosting
          wrote on last edited by
          #7

          Right now it is not freezing. I just need to figure out how to populate this combo box with the teacher names. Here is my code for cloning the datasource. I tried doing it several ways.

          ' query
                  tableName = "tbl_teachers"
                  dtTeachName = generalQuery()
          
                  ' fill the teachers checked list box
                  lstTeachers.DataSource = dtTeachName
                  lstTeachers.DisplayMember = "teach_name"
                  lstTeachers.ValueMember = "teach_id"
                  cboSchedDur.SelectedItem = "This Week"
                  'End If
          
                  ' fill the teachers checked list box
                  dtTNameClone = dtTeachName.Clone()
                  cboSelectTeacher.DataSource = dtTNameClone
                  cboSelectTeacher.DisplayMember = "teach_name"
                  cboSelectTeacher.ValueMember = "teach_id"
          
          C 1 Reply Last reply
          0
          • A AAGTHosting

            Right now it is not freezing. I just need to figure out how to populate this combo box with the teacher names. Here is my code for cloning the datasource. I tried doing it several ways.

            ' query
                    tableName = "tbl_teachers"
                    dtTeachName = generalQuery()
            
                    ' fill the teachers checked list box
                    lstTeachers.DataSource = dtTeachName
                    lstTeachers.DisplayMember = "teach_name"
                    lstTeachers.ValueMember = "teach_id"
                    cboSchedDur.SelectedItem = "This Week"
                    'End If
            
                    ' fill the teachers checked list box
                    dtTNameClone = dtTeachName.Clone()
                    cboSelectTeacher.DataSource = dtTNameClone
                    cboSelectTeacher.DisplayMember = "teach_name"
                    cboSelectTeacher.ValueMember = "teach_id"
            
            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #8

            does dtTeachName contain any data ? If it does, it should be showing.

            Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

            A 1 Reply Last reply
            0
            • C Christian Graus

              does dtTeachName contain any data ? If it does, it should be showing.

              Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

              A Offline
              A Offline
              AAGTHosting
              wrote on last edited by
              #9

              It does show data. I populated another list box from the data, but when I make the copy it does not fill the combo box. The list box and the combo box are filled in 2 different sub procedures. The dataTables that I am using are declared globally in a module as public.

              C 1 Reply Last reply
              0
              • A AAGTHosting

                It does show data. I populated another list box from the data, but when I make the copy it does not fill the combo box. The list box and the combo box are filled in 2 different sub procedures. The dataTables that I am using are declared globally in a module as public.

                C Offline
                C Offline
                Christian Graus
                wrote on last edited by
                #10

                AAGTHosting wrote:

                The dataTables that I am using are declared globally in a module as public.

                Well, they should exist solely for the control that's using them, making one global like htat is a poor design.

                Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

                A 1 Reply Last reply
                0
                • C Christian Graus

                  AAGTHosting wrote:

                  The dataTables that I am using are declared globally in a module as public.

                  Well, they should exist solely for the control that's using them, making one global like htat is a poor design.

                  Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

                  A Offline
                  A Offline
                  AAGTHosting
                  wrote on last edited by
                  #11

                  I tried declaring local dataTables and it still does not work. I just ran the same query again and the list box populated, but when I click on the students button to go to that panel all the controls on the panel do not come up. Here is my query. Would it be better for me to use a GetDataBy query instead of a fillBy? The GetDataBy method returns a dataTable.

                  C 1 Reply Last reply
                  0
                  • A AAGTHosting

                    I tried declaring local dataTables and it still does not work. I just ran the same query again and the list box populated, but when I click on the students button to go to that panel all the controls on the panel do not come up. Here is my query. Would it be better for me to use a GetDataBy query instead of a fillBy? The GetDataBy method returns a dataTable.

                    C Offline
                    C Offline
                    Christian Graus
                    wrote on last edited by
                    #12

                    Where is your query ? Sounds like what you're really saying is that you have a button event which is not working, have you set a breakpoint in there ?

                    Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

                    A 1 Reply Last reply
                    0
                    • C Christian Graus

                      Where is your query ? Sounds like what you're really saying is that you have a button event which is not working, have you set a breakpoint in there ?

                      Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

                      A Offline
                      A Offline
                      AAGTHosting
                      wrote on last edited by
                      #13

                      This only seems to happen when I try to populate the second teacher list box. If I comment out the code to bind a source to the teacher combo box then only the first name on the list of teachers shows up in the teacher list box, then when I click on the students button one of my list boxes shows up, that is not filled dynamically and you can't select a type of student. Should I use multiple datasets so I don't have multiple controls getting info from the tables in the dataset?

                      1 Reply Last reply
                      0
                      • C Christian Graus

                        You can't bind two controls to the same source, you need to make a copy.

                        Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

                        J Offline
                        J Offline
                        jimpar
                        wrote on last edited by
                        #14

                        you can bind multiple combo boxes to the same dataTable if each has its own binding source

                        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