Listview - Select (and stay selected) on click?
I think im being stupid about this.. or maybe its too early.... lol
I am trying to make my Listview a select/deselect by click (like checked) so you can select multiple rows without having to hold shift.
click selects it, click again on that row and it deselects it?
Re: Listview - Select (and stay selected) on click?
I once needed to implement this using drag. Maybe you could modifies it to suit your needs
vb Code:
Public Class Form1
Private m_mouseDown As Boolean
Private Sub ListView1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseDown
Me.m_mouseDown = True
End Sub
Private Sub ListView1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseDown
If Me.m_mouseDown Then
Dim i = ListView1.HitTest(e.Location).Item.Index
ListView1.Items(i).Selected = True
End If
End Sub
Private Sub ListView1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseUp
Me.m_mouseDown = False
End Sub
End Class
Re: Listview - Select (and stay selected) on click?
ooo! Hittest! forgot about that.. brb thanks!
EDIT: it wont "stick" unless i move the mouse off the line...
Re: Listview - Select (and stay selected) on click?
I guess creating a List(Of Integer) would be sloppy hmm
Re: Listview - Select (and stay selected) on click?
bah.. thought this would work
Code:
Private Sub LV1_MouseClick(sender As Object, e As MouseEventArgs) Handles LV1.MouseClick
Dim ITM As ListViewItem = LV1.Items(LV1.HitTest(e.Location).Item.Index)
For Each LI As ListViewItem In LV1.SelectedItems
If LI Is ITM Then LI.Selected = Not LI.Selected
If LI.SubItems(2).Text = WeekOf.ToString Then LI.Selected = False 'This is making sure you dont pick the current week row...
Next
End Sub
but its deselecting the one i just selected...
also sloppy...
Code:
Private Sub LV1_MouseClick(sender As Object, e As MouseEventArgs) Handles LV1.MouseClick
Dim ITM As ListViewItem = LV1.Items(LV1.HitTest(e.Location).Item.Index)
If ITM.SubItems(10).Text = "0" Then ITM.SubItems(10).Text = "1" Else ITM.SubItems(10).Text = "0"
For Each LI As ListViewItem In LV1.Items
If LI.SubItems(10).Text = "1" Then LI.Selected = True Else LI.Selected = False
If LI.SubItems(2).Text = WeekOf.ToString Then LI.Selected = False : LI.SubItems(10).Text = "0" 'This is making sure you dont pick the current week row...
Next
End Sub
but it works... it just seems wrong lol
EDIT: i didnt even think of using a list! lol thats better than a "flag"
so creating a boolean list works also...
Dim ListItemSelected As New List(Of Boolean)
Code:
Private Sub LV1_MouseClick(sender As Object, e As MouseEventArgs) Handles LV1.MouseClick
Dim I As Integer = LV1.HitTest(e.Location).Item.Index
ListItemSelected(I) = Not ListItemSelected(I)
For Each LI As ListViewItem In LV1.Items
LI.Selected = ListItemSelected(LI.Index)
If LI.SubItems(2).Text = WeekOf.ToString Then LI.Selected = False 'This is making sure you dont pick the current week row...
Next
End Sub
but again... seems a bit sloppy lol - better than my idea though!
Re: Listview - Select (and stay selected) on click?
Because you deselect it.
Code:
If LI Is ITM Then LI.Selected = Not LI.Selected
Re: Listview - Select (and stay selected) on click?
yeah... i was thinking the "selection" occurred after the click. nope! lol
you list idea is the best so far though.