Jump to content

Recommended Posts

Posted

This is a general question about VB.Net rather than AutoCAD VB.Net but I think the question is general.

 

In the past (VB6) I have created an array of radio buttons by copy & paste which gives me something like

 

 
button1(0), button1(1), button1(n)

and

 
button2(0), button2(1), button2(n)

 

where button1 and button2 worked as independant groups.

 

It would appear that in VB.Net you can't (I can't?) create an array of buttons. I can get them to behave as a group by putting them in a container but it looks harder to check which one is selected. Have I missed something?

Posted

Try something like this in your form load event:

 

        optLine.Checked = True
       optSymbol.Checked = False
       optPoint.Checked = False

That sets the initial state of the option buttons.

 

Then use this to change their states:

 

            If crCodeLine.sType = "Line" Then
               optLine.Checked = True
           ElseIf crCodeLine.sType = "Symbol" Then
               optSymbol.Checked = True
           Else
               optPoint.Checked = True
           End If

To read their states use:

 

        If optLine.Checked = True Then
           strType = "Line"
       ElseIf optSymbol.Checked = True Then
           strType = "Symbol"
       Else
           strType = "Point"
       End If

Or if you have a lot of them you can use a case select instead of if statements.

Posted

Thanks Tyke. do you have to use containers to group them or can you mix twodifferent sets within one container?

 

I have been using CASE SELECT based on the array position. Do I look at the opt.Name to work it now?

Posted

You need each set of radio buttons in their own GroupBox, as when you change the state of one to 'checked' ALL of the others in the container are then automatically set as 'unchecked'. If you don't want to see the GroupBox Text set its Text property to an empty string.

 

To work the radio buttons you have to use their names and properties (eg 'optLine.Checked = True'). I still use the prefix 'opt' for radio button names, but that is just a hangover from VBA where they are called option buttons.

Posted

Thanks again, it sounds like I am heading in the right direction then. I too prefer optName.

 

One more (?) question.

 

With an array it is easy to set which opt is highlighted....

 

 
optButton1(x).checked=true

is this possible just given x or do you have to do a case|select?

Posted

Not as far as I know. You have to use the radio button's name.

 

Perhaps I misled you a bit with the case select possibility. I use it when setting the radio buttons, if a condition is true then set the relevant radio button to checked.

 

This:

           If crCodeLine.sType = "Line" Then
                 optLine.Checked = True             
           ElseIf crCodeLine.sType = "Symbol" Then
                optSymbol.Checked = True
            Else
                optPoint.Checked = True
            End If

 

would become:

       Select Case crCodeLine.sType

           Case "Line"
               optLine.Checked = True

           Case "Symbol"
               optSymbol.Checked = True

           Case Else
               optPoint.Checked = True

       End Select

 

You can't loop through all of the radio buttons in your GroupBox using Select Case.

Posted

I read a value from the registry so I can do something like this...

 

 
Select Case myValue
case = 1
optButton.checked=true

etc. It works but its a lot longer than the one I posted above. I'm just glad I've only got 8 elements. :)

Posted

That's correct. Who ever said .NET was more concise than VB6? We all know much better than that Dave. Perhaps that's one reason why I still do VBA as well as .NET.

 

But at least you only have to mark one of the radio buttons as checked, all the others in the GroupBpx then automatically become unchecked.

 

Keep on coding ;) you never know when BB might show up :shock:

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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...