Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

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)

Posted

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.

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)

Posted

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

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)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...