SelectIndexChanged Event for array of Combobox.

manasi

Member
Joined
Jul 19, 2006
Messages
15
Programming Experience
Beginner
Hi all !!

I am working with ComboBox control defined in the code of form itself.

I have created an array of ComboBox control , say Dim cb(5) as ComboBox, and want to disable another Combobox, say Dim cbox as ComboBox, on the selection of particular text from one of these cb(5).

Moreover, its not possible using SelecedTextChanged event for an array of combobox as we do in a typical manner for a normal single Combobox.(as it is an array of combobox.)

So how to use SelectedTextChanged event for array of combobox?

The code is as follows :-

Public Class CPanelcomp
Inherits System.Windows.Forms.Form

Public cb(5), cbox As ComboBox
Dim i As Integer
Dim frm as New CPanelcomp

Windows Form Designer generated code
.
.
Public Sub ComboItemSelected()

For i = 0 To cb.Length
If cb(i).SelectedItem.Equals("NO") Then '**** if the selected Item
cbox.Enabled = False '**** from array of combobox
End If '**** is "NO", another combobox
Next '**** should be disabled.

End Sub


Private Sub CPanelcomp_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For i = 0 To str.Length() - 1
cb = New ComboBox
cb(i).Text() = "SELECT"
cb(i).Items.Add("YES")
cb(i).Items.Add("NO")
Next

frm.ComboItemSelected() ' CODE IS NOT WORKING HERE
End Sub


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'////Button1 is button control on the form

frm.ComboItemSelected()

End Sub


Can anybody tell me how to perform any further operation/handling event on the selection of item from the array of combobox?? How to use SelectedIndexChanged event explicitly for array of combobox???

I would really appreciate if someone would sort out the problem.

Thanks,
Manasi
 
Attach/remove event handler dynamically in code with AddHandler and RemoveHandler statements. Example:
VB.NET:
AddHandler cb.SelectedIndexChanged, AddressOf mySelectedIndexChanged
You see the addressof part points to a event handler method 'mySelectedIndexChanged' that must have the same method signature as the event it is to handle. Example:
VB.NET:
Private Sub mySelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
  'code here
End Sub
You can use the same event handler method for several controls, the 'sender' parameter is a reference to the control that raised the event.
 
Back
Top