Select a Whole Row in Any ListView

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


Share the Post: