ActiveControl not reporting correctly - Bug?

bjwade62

Well-known member
Joined
May 25, 2006
Messages
50
Programming Experience
3-5
I recently moved a listview control inside a SplitContainer. The problem is the ActiveControl is the SplitControl not the listview inside it. Bug?? It worked fine as is until I put the ListView in the SplitterControl.
I have a contextmenu_click event containing the following code.

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

 
Instead of coding "ActiveControl.Name", which implies "Me.ActiveControl.Name" and return the active control on the form, use your SplitContainer to search for active control within:
VB.NET:
If SplitContainer1.ActiveControl Is lvwLeftList Then
  '...
ElseIf SplitContainer1.ActiveControl Is lvwRightList Then
  '...
End If
 
Works Great! Thanks.

JohnH said:
Instead of coding "ActiveControl.Name", which implies "Me.ActiveControl.Name" and return the active control on the form, use your SplitContainer to search for active control within:
VB.NET:
If SplitContainer1.ActiveControl Is lvwLeftList Then
  '...
ElseIf SplitContainer1.ActiveControl Is lvwRightList Then
  '...
End If
 
Back
Top