devxlogo

Select a Whole Row in Any ListView

Only in VB6 do the common controls OCX files provide an option to select a full line in a listview. In earlier versions, you can select a ListItem only by clicking on the left-most column. This code allows the user to click anywhere on the line to select and highlight the ListItem:

 Private Sub ListView1_MouseDown(Button As _Integer, Shift As Integer, x As Single, y _As Single)Dim itm As ListItemDim i As LongWith ListView1Set .DropHighlight = _.HitTest(Screen.TwipsPerPixelX * 2, y)Set itm = .HitTest(Screen. _TwipsPerPixelX * 2, y)Set .SelectedItem = itm' Use the following if you have code' to execute on a user click.For i = 1 To .ListItems.Count Step 1If .ListItems(i).Selected ThenCall ListView1_ItemClick _(.ListItems(i))Exit ForEnd IfNext iEnd WithEnd Sub

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  Five Early Architecture Decisions That Quietly Get Expensive

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.