Question

I have an INI file that stores the selected radio box on exit. It's like:

[Settings] SearchWhat=RadioButtonName

When my form loads I am wanting to take that name and set it as checked. I tried:

 Dim searchwhat = ini.ReadValue("settings", "searchwhat")
 searchwhat.checked = True

But that returns the error: checked' is not a member of 'String'

That INI function gives the value but I can't figure out to "make it true"

MTIA

Was it helpful?

Solution

Use the Controls.Find() function like this:

Dim searchwhat As String = ini.ReadValue("settings", "searchwhat")
Dim matches() As Control = Me.Controls.Find(searchwhat, True)
If matches.Length > 0 AndAlso TypeOf matches(0) Is RadioButton Then
    Dim rb As RadioButton = DirectCast(matches(0), RadioButton)
    rb.Checked = True
End If
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top