ActiveControl not reporting correctly - Bug?

bjwade62

Centurion
Joined
Oct 31, 2003
Messages
104
I recently moved a listview control inside a SplitContainer. I have a contextmenu_click event containing the following code.
Visual Basic:
If ActiveControl.Name = lvwLeftList.Name Then...
The problem is the ActiveControl is the SplitControl not the listview inside it. Bug??
 
Are you using it under the correct circumstances?
MSDN said:
In order to receive a valid value from this property, the object that calls it must either contain or be contained in the control it is calling. If one form tries to call another form's ActiveControl properties, it will receive an undefined value. In this case, you need to define your own communication mechanism between the forms to pass this data
And you are sure that the ListView has focus when this code is being executed, right? How is the context menu being displayed? Via the ContextMenu property of the control?
 
Yes the list view has focus. I'm using button2 to active a ContextMenu. Is that what you mean? Thanks.
 
Sure, here it is. It worked fine as is until I put the ListView in the SplitterControl. Thanks again.

Visual Basic:
    Private Sub cmnuSelectAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmnuSelectAll.Click
        If ActiveControl.Name = lvwLeftList.Name Then
            Dim ListLeft As ListViewItem
            For Each ListLeft In lvwLeftList.Items
                If ListLeft.ImageIndex <> 5 Then
                    ListLeft.Selected = True
                End If
            Next
        End If
        If ActiveControl.Name = lvwRightList.Name Then
            Dim ListRight As ListViewItem
            For Each ListRight In lvwRightList.Items
                If ListRight.ImageIndex <> 5 Then
                    ListRight.Selected = True
                End If
            Next
        End If
    End Sub


marble_eater said:
Can you post the code that shows the menu?
 
Here's the solution in case anyone else needs it in the future.

If SplitContainer1.ActiveControl Is lvwLeftList Then
'...
ElseIf SplitContainer1.ActiveControl Is lvwRightList Then
'...
End If

Got it from someone at another forum.

marble_eater said:
Can you post the code that shows the menu?
 
Back
Top