|
-
May 16th, 2013, 07:34 AM
#1
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?
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
May 16th, 2013, 07:57 AM
#2
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
-
May 16th, 2013, 08:10 AM
#3
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...
Last edited by Static; May 16th, 2013 at 08:16 AM.
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
May 16th, 2013, 08:26 AM
#4
Re: Listview - Select (and stay selected) on click?
I guess creating a List(Of Integer) would be sloppy hmm
-
May 16th, 2013, 08:26 AM
#5
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!
Last edited by Static; May 16th, 2013 at 08:45 AM.
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
May 16th, 2013, 08:39 AM
#6
Re: Listview - Select (and stay selected) on click?
Because you deselect it.
Code:
If LI Is ITM Then LI.Selected = Not LI.Selected
-
May 16th, 2013, 08:46 AM
#7
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.
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|