Listview control losing highlight when focus on textbox RRS feed

  • Question


    I have a listview control. The user highlights a row in the listview control and the entry appears in a textbox. The problem is that when they click the textbox to edit the entry, the listview control row that is selected/highlighted is unselected.

    I'm sure others have run into this annoying problem.

    Can anyone offer a solution to this dilemma? Thank you for your time.


    I have tried the HideSelection = False property, but it did not work.


    Code Block

    Public Class frmMain


    Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


    End Sub


    Private Sub populate()


    'initialize the listview

    Dim listItem As ListViewItem = Nothing




    'fill listview


    With Me.ListView1

    .GridLines = True

    .MultiSelect = False

    .FullRowSelect = True

    .HideSelection = False

    .View = View.Details

    .Columns.Add("TEST", 225, HorizontalAlignment.Left)

    End With


    'populate the columns

    For i As Integer = 0 To 5

    listItem = New ListViewItem

    listItem.Text = ("ASDF")




    'end fill

    End Sub


    Private Sub ListView1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.Click

    Me.TextBox1.Text = Me.ListView1.SelectedItems(0).SubItems(0).Text

    End Sub



    Wednesday, December 12, 2007 12:58 PM


  • Have copied your code into a new application and run it.

    It works fine.


    Even added a button, to confirm the item you selected.

    Code Block

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        If ListView1.SelectedItems.Count > 0 Then


        End If

    End Sub



    What does happen, when the ListView loses focus, the selected item reverts to a "lost focus" colour.

    Are you running your app with a reduced colour palette (Citrix environment for example), or have a Windows theme applied that affects the Windows system colours ?

    Wednesday, December 12, 2007 1:50 PM