Accessing Properties within a Panel

A

ally

In VB 2K5 Express I've created a panel named "Configure" with eight
label, and eight combobox controls; and finally a button named
"Apply."

The label controls are sequentially named Channel0 through Channel7,
and the combobox controls are sequentially named Ch0 through Ch7,
accordingly.

Each combobox contains four items out of which one must be selected.
For example, lets say we choose Channel3 and the corresponding combox
box drops down with these choices:

Analog
State
Counter
Pdm

After any or all Channels have been configured, I want to use the
Apply button's click event to process the selections.

My question is, "From within the APPLY buttons click event code, how
can I determine what item each of the eight combobox controls contain?

(I'm kind of thinking in terms of finding some way to index through
each of the comboboxes using a loop structure, but I don't see any
index value for the combobox controls in the panel.)

Thanks for helping this novice.
 
C

Cor Ligthert [MVP]

Ally,

Combobox.text (do not forget to set them initial to Selectedinded = 0)
As well to set them to dropdownlist

I hope this helps,

Cor
 
A

Al Reid

In VB 2K5 Express I've created a panel named "Configure" with eight
label, and eight combobox controls; and finally a button named
"Apply."

The label controls are sequentially named Channel0 through Channel7,
and the combobox controls are sequentially named Ch0 through Ch7,
accordingly.

Each combobox contains four items out of which one must be selected.
For example, lets say we choose Channel3 and the corresponding combox
box drops down with these choices:

Analog
State
Counter
Pdm

After any or all Channels have been configured, I want to use the
Apply button's click event to process the selections.

My question is, "From within the APPLY buttons click event code, how
can I determine what item each of the eight combobox controls contain?

(I'm kind of thinking in terms of finding some way to index through
each of the comboboxes using a loop structure, but I don't see any
index value for the combobox controls in the panel.)

Thanks for helping this novice.

You can iterate through the controls on the Panel using the following:
(warning: Air code - not tested)

For Each cal as Control In Configure.Controls
If TypeOf cal is ComboBox Then

'Do whatever you need to do with the ComboBoxes.

End If
Next

I hope this helps.
 
L

Larry Lard

You're wondering what happened to control arrays, right?
You can iterate through the controls on the Panel using the following:
(warning: Air code - not tested)

For Each cal as Control In Configure.Controls
If TypeOf cal is ComboBox Then

'Do whatever you need to do with the ComboBoxes.

End If
Next

That works. Or, you can even create your own control array! Remember,
Control is a class like any other, so there's nothing stopping us
creating an array of Control, or even of ComboBox:

'at form level
Private panelCombos() As ComboBox

'at form Load
panelCombos = New Combobox() { Ch0, Ch1, Ch2, Ch3, Ch4, Ch5, Ch6, Ch7 }

'when we want to read the values
Dim iCombo As Integer
For iCombo = 0 To panelCombos.Length - 1
DoSomethingWith panelCombos(i).SelectedItem
Next
 
A

ally

You're wondering what happened to control arrays, right?


That works. Or, you can even create your own control array! Remember,
Control is a class like any other, so there's nothing stopping us
creating an array of Control, or even of ComboBox:

'at form level
Private panelCombos() As ComboBox

'at form Load
panelCombos = New Combobox() { Ch0, Ch1, Ch2, Ch3, Ch4, Ch5, Ch6, Ch7 }

'when we want to read the values
Dim iCombo As Integer
For iCombo = 0 To panelCombos.Length - 1
DoSomethingWith panelCombos(i).SelectedItem
Next

Thanks, Al ... mission accomplished on that one. While speaking of
control arrays, I also need to create a "cellular" control array. In
this panel I have 8 rows by 5 columns and each cell has a textbox
control. So there are 8 * 5 = 40 cells. How could I modify your
technique to include a double dimension to fit this scenario? Namely
something like:

panelCombos = New Combobox(m,n) {textbox(m,n) }

is what I was thinking of, which is just a wild guess on my part.

Thank you very much for your insight!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top