Events and loss of control indexing

On an event, the sender is associated with the control that initiated the event. Through DirectCast I can retrieve information about that control and store the information into an array or several arrays. At the same time, I need to change the state of a different type of control. These two controls are located next to each other on the same form. I know my position within the array by DirectCasting the Object sender.

How do I change the CheckState of the CheckBox that sits to the right of the TextBox which generated the event



Answer this question

Events and loss of control indexing

  • vic_

    Just after I posted it hit me:

    Private
    Sub TextBox1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Leave, TextBox2.Leave...

    Dim ItemIDs(9) As String
    Dim Handles(9) As Short
    Dim checkBox() As CheckBox = {checkBox1, checkBox2} ' Initialize array with existing CheckBox names
    Dim index = DirectCast(sender, TextBox).Tag

    ItemIDs(index) =
    DirectCast(sender, TextBox).Text
    Handles(index) =
    DirectCast(sender, TextBox).Tag
    checkBox(index).CheckState = CheckState.Checked
    End Sub

    The contents of the checkBox array points to the specific CheckBox control. That was an understanding I was looking for. checkBox(index) Inherits from CheckBox. Very cool!

    I have 10 TextBoxes in a column with several controls to the right of each TextBox. The user may or may not start at the first TextBox. I need to work with the entire row of controls after the user Leaves the TextBox.

    At the end of the day, I've got atleast 6 single dimension arrays to intialize.

    I now know what to do, thanks for responding.


  • e-roo

    If you have all of the controls in an array and they are in the proper format then when one event is triggered
    SomeEvent(sender as Object, e as Eventargs
    Dim Index as Int32 = Array.IndexOf(ControlArray, sender);
    if Index > -1 then
    Control TmpControl = ControlArray(Index)
    Dim TmpCast as CheckBox = CType(TmpControl, CheckBox)
    TmpCast.Checked = true
    '... etc
    '(I think)
    end if


  • Events and loss of control indexing