listview control problem
-
Hi every body , i have a problem ?? i have a list view control in windows application , and i set its chcek property to true i want if the user Check an item to make all other items unchecek and i don't know how :confused: ? i try too much but it doesnot work Can You help me how to do it ?? Thanks Mona .
LA ELAH ELA ALLAH MOHAMED RASOL ALLAH
-
Hi every body , i have a problem ?? i have a list view control in windows application , and i set its chcek property to true i want if the user Check an item to make all other items unchecek and i don't know how :confused: ? i try too much but it doesnot work Can You help me how to do it ?? Thanks Mona .
LA ELAH ELA ALLAH MOHAMED RASOL ALLAH
You'd have to handle the ItemChecked event of the ListView, which will give you the item that was clicked on. You'd then have to set a static flag in the event handler that will signal that you are changing check marks. Iterate over the items in the list, changing each check mark, then reset the flag. Since changing the check mark will fire the same event again, the handler code has to start by check that flag. If it's set, then the handler code can exit without making any changes. But, wouldn't this be a job for RadioButtons?? After all, this is exactly what they do.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
You'd have to handle the ItemChecked event of the ListView, which will give you the item that was clicked on. You'd then have to set a static flag in the event handler that will signal that you are changing check marks. Iterate over the items in the list, changing each check mark, then reset the flag. Since changing the check mark will fire the same event again, the handler code has to start by check that flag. If it's set, then the handler code can exit without making any changes. But, wouldn't this be a job for RadioButtons?? After all, this is exactly what they do.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
thanks for your replay but can you mak it more simple , sorry i am new in vb so can u explain with code , it'll be better and easy to understand Thanks a lot Mona :|
LA ELAH ELA ALLAH MOHAMED RASOL ALLAH
Hello, Please try this code. I believe this should assist you.
Private Sub ListView1_ItemCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles ListView1.ItemCheck For i As Integer = 0 To Me.ListView1.Items.Count - 1 If i <> e.Index Then Me.ListView1.Items(i).Checked = False End If Next End Sub
Regards, AllenAllen Smith Software Engineer ComponentOne LLC www.componentone.com
-
thanks for your replay but can you mak it more simple , sorry i am new in vb so can u explain with code , it'll be better and easy to understand Thanks a lot Mona :|
LA ELAH ELA ALLAH MOHAMED RASOL ALLAH
or another one
If Bloading the exit sub bLoading = true For each oItem as Listview item in LVData.items oitem.checked = true next
Never underestimate the power of human stupidity RAH