Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiselect ListView Without ctrl

Status
Not open for further replies.

daveonion

Programmer
Aug 21, 2002
359
GB
Hi,

I am creating an app which will be touch screen, I have a listview and i want the user to be able to select, deselect items by clicking once on each item. The problem is currently you have to hold ctrl down to select multiple does anybody know how to do it without ctrl.
Thanks in advance
 
Why don't you forgo the .SelectedItems collection and just go with .CheckedItems? CheckedItems is more inline with what you are doing. I understand you are using a touchscreen, and it would be difficult to force the user to touch on the checkbox, but you could use the following code to check the item once touched.

Code:
Public Class Form2
    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.ListView1.HideSelection = True
        Me.ListView1.MultiSelect = False
    End Sub

    Private Sub ListView1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseDown
        Dim lvi As ListViewItem = Me.ListView1.GetItemAt(e.X, e.Y)
        If Not lvi Is Nothing Then
            lvi.Checked = Not lvi.Checked
            If lvi.Checked Then lvi.BackColor = Color.Blue : lvi.ForeColor = Color.White Else lvi.BackColor = Color.White : lvi.ForeColor = Color.Black
        End If
    End Sub
End Class
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top