Results 1 to 3 of 3

Thread: ActiveControl not reporting correctly - Bug?

  1. #1
    bjwade62's Avatar
    bjwade62 is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    May 2006
    Posts
    50
    Reputation
    89

    Unhappy ActiveControl not reporting correctly - Bug?

    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


  2. #2
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,177
    Reputation
    2368
    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:
    Code:
    If SplitContainer1.ActiveControl Is lvwLeftList Then
      '...
    ElseIf SplitContainer1.ActiveControl Is lvwRightList Then
      '...
    End If

  3. #3
    bjwade62's Avatar
    bjwade62 is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    May 2006
    Posts
    50
    Reputation
    89
    Works Great! Thanks.

    Quote Originally Posted by JohnH
    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:
    Code:
    If SplitContainer1.ActiveControl Is lvwLeftList Then
      '...
    ElseIf SplitContainer1.ActiveControl Is lvwRightList Then
      '...
    End If

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking