|
-
February 5th, 2003, 03:33 PM
#1
Changing checkbox state of listviewitem form code
Task:
I have a listview with checkboxes. The idear is that the only one item in the listview can be checked at one time. So when the user clicks on a new item the all other items should be unchecked (the other item).
My solution:
in the listview1_ItemCheck event I put code to uncheck the old item, ei:
Olditem.checked = CheckState.Unchecked
Problem:
this line of code
Olditem.checked = CheckState.Unchecked
makes the listview1_ItemCheck event fire again and thus causing an endless loop.....
Somebody.............Please help, this is not how it was in VB6...I know that some of you hate the remark.
-
February 5th, 2003, 04:07 PM
#2
Try this:
Private Sub ListView1_ItemCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles ListView1.ItemCheck
If e.NewValue = CheckState.Checked Then
If Not oldItem Is Nothing Then
oldItem.Checked = False
End If
oldItem = ListView1.Items(e.Index)
Else
'Nothing
End If
End Sub
-
February 5th, 2003, 04:21 PM
#3
It did the job...Cheers!!
Originally posted by DSJ
Try this:
Private Sub ListView1_ItemCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles ListView1.ItemCheck
If e.NewValue = CheckState.Checked Then
If Not oldItem Is Nothing Then
oldItem.Checked = False
End If
oldItem = ListView1.Items(e.Index)
Else
'Nothing
End If
End Sub
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
|