filling 2 different combo boxes with info from same dataTable
-
I have a list box and a combo box that both allow you to select a teachers name from a list. They are on different panels that show on the form at different times. I created a dataTable named dtTeachName that only holds the teacher name and id. I am attempting to populate both of these controls with the saem information. At first I loaded both of these from the same dataTable, but when I do that the teacher names will dissapear in the list box. I even put an if statement that said that that list box wont populate unless the panel it is on is visible. When I do that the program freezes. Has anyone run into this problem before? Here is my code.
' fill the teachers checked list box cboSelectTeacher.DataSource = dtTeachName cboSelectTeacher.DisplayMember = "teach_name" cboSelectTeacher.ValueMember = "teach_id" ' fill the teachers checked list box lstTeachers.DataSource = dtTeachName lstTeachers.DisplayMember = "teach_name" lstTeachers.ValueMember = "teach_id"
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 )
-
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 )
How do I make a copy? Do I just do another query or literally make a copy?
-
How do I make a copy? Do I just do another query or literally make a copy?
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 )
-
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 )
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.
-
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.
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 )
-
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 )
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"
-
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"
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 )
-
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 )
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.
-
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.
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 )
-
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 )
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.
-
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.
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 )
-
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 )
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?
-
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 )