mike55 Posted January 13, 2009 Posted January 13, 2009 Hi I am using the following code: Private Sub ReloadSelectionCriteria(ByVal userSelection As Hashtable) For Each entry As DictionaryEntry In userSelection CType(Controls(entry.Key), ComboBox).SelectedItem = entry.Value Next End Sub to loop through all the keys in a hash table. All the keys are the names of a valid combobox displayed on screen. What I am trying to do is to reflect the values chosen on the comboboxes on the parent screen through to the child screen. However, with the above code I am getting a NullReferenceException. Any suggestions? I believe that the problem is that my code cannot find the control on the windows form. Mike55. Quote A Client refers to the person who incurs the development cost. A Customer refers to the person that pays to use the product. ------ My software never has bugs. It just develops random features. (Mosabama vbforums.com)
mike55 Posted January 13, 2009 Author Posted January 13, 2009 Fixed my initial problem: Private Sub ReloadSelectionCriteria(ByVal userSelection As Hashtable, ByVal parent As Object) Dim myC() As Control For Each entry As DictionaryEntry In userSelection myC = Controls.Find(entry.Key.ToString, True) CType(myC(0), ComboBox).SelectedIndex = entry.Value Next End Sub I now have an additional issue, the form that I am using is an instance of the parent form and both of them remain open on screen. When I cycle through the hashtable, the above code is simply looking at the parent form. How can I re-target it at the child form? Mike55. Quote A Client refers to the person who incurs the development cost. A Customer refers to the person that pays to use the product. ------ My software never has bugs. It just develops random features. (Mosabama vbforums.com)
mike55 Posted January 13, 2009 Author Posted January 13, 2009 Solution: Private Sub ReloadSelectionCriteria(ByVal userSelection As Hashtable, ByVal parent As Object) Dim myC() As Control For Each entry As DictionaryEntry In userSelection myC = parent.Controls.Find(entry.Key.ToString, True) CType(myC(0), ComboBox).SelectedIndex = entry.Value Next End Sub Quote A Client refers to the person who incurs the development cost. A Customer refers to the person that pays to use the product. ------ My software never has bugs. It just develops random features. (Mosabama vbforums.com)
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.