[VB.NET] String to object

Soldato
Joined
12 Jun 2005
Posts
5,361
Hi there,

I have a string which refers to a name of an object on my form.

How do i convert the string to an object....if that makes sense.

Thanks.
 
As Haircut says, you'll need to use reflection to do this.

Why do you need to do it in the first place? It's very rarely necessary to do this sort of thing, so I suspect there's a better way. :)
 
I am trying to create a class which i could easily transfer to another application and since there doesn't seem to be control arrays, i need to construct the name with an increamenting number on the end.

Thanks.
 
What do you mean when you say 'easily transfer to another application'?

Control Arrays aren't present in VB.NET because they aren't neeeded.
The fact that you can create controls on the fly and assign event handlers in code means the concept of a control array is redundant.

I don't suppose you really need reflection to do this. Any chance of a bit more detailed explanation?
 
Yeah, sure.

Basically, I current have 5 combobox boxes on my form, all with the same list of options. When i select an option in any of the 5 comboboxes, it takes that option off the four other combo boxes.

Basically, what i want to be able to do, is create a class where i pass in the combobox that just had an option selected and the number of combo boxes and it update all the other combo boxes on the form.

Currently, i have it working where i pass in the combobox that just had an option selected and a list of the comboboxes.

Here it is:

Code:
    Private Sub BoxSelected(ByVal SelectedCombo As ComboBox, ByVal clist As List(Of ComboBox))

        Dim a As Integer
        Dim startValues As New List(Of String)
        Dim ComboList As New List(Of Object)

        For Each Item As Object In clist
            If Item.Tag <> SelectedCombo.Tag Then
                ComboList.Add(Item)
                startValues.Add(Item.SelectedItem)
                Item.Items.Clear()
            End If
        Next

        For Each Item As String In sList
            If Item <> SelectedCombo.SelectedItem And Not startValues.Contains(Item) Then
                For Each Obj As Object In ComboList
                    Obj.Items.Add(Item)
                Next
            End If
        Next

        sChanged = False

        a = 0

        For Each Item As String In startValues
            If Item <> "" Then ComboList(a).Items.Add(Item)
            ComboList(a).SelectedItem = startValues(a)
            a += 1
        Next

    End Sub
 
Back
Top Bottom