listview - count checked items
Hope someone can help..........
Code:
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked = True Then
For Each CheckedApp As ListViewItem In App_List.Items
CheckedApp.Checked = True
Button1.Text = "Start installing (" + App_List.Items.Count > -1 + " apps.)"
Next
ElseIf CheckBox1.Checked = False Then
For Each CheckedItem As ListViewItem In App_List.Items
CheckedItem.Checked = False
Next
End If
End Sub
problem, checkbox1 isn't checking items and the button text, i not sure works....
Re: listview - count checked items
Your question (and I use the term loosely) doesn't really make sense. The title mentions counting checked items but your code doesn't seem to have anything to do with counting. I'm guessing that English is not your first language but please try to provide a FULL and CLEAR explanation of what you're actually trying to achieve instead of expecting us to work it out from code that doesn't actually work.
Re: listview - count checked items
I don't understand the question either...
Re: listview - count checked items
Code:
Button1.Text = "Start installing (" + App_List.Items.Count > -1 + " apps.)"
Shouldn't that be
Code:
Button1.Text = "Start installing (" + (App_List.Items.Count - 1).ToString() + " apps.)"
?
Other than that, I can't really guess what's wrong.
Re: listview - count checked items
formlesstree4 is right, but also you're resetting Button1.Text for every item in your loop. in vb2012:
Code:
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
Array.ForEach(App_List.Items.Cast(Of ListViewItem).ToArray, Sub(lvi) lvi.Checked = CheckBox1.Checked)
Button1.Text = If(CheckBox1.Checked, "Start installing (" + (App_List.Items.Count > -1).ToString + " apps.)", "some other string")
End Sub
Re: listview - count checked items
Checkbox1 should check allitems in listtview but is not...
and am not sure if the button text that counts, works..
Re: listview - count checked items
try my code from post #5
I tested it + I know it works, as does your original code with formlesstree4's modification
Re: listview - count checked items
I got error: Error 1 'Cast' is not a member of 'System.Windows.Forms.ListView.ListViewItemCollection'. H:\X17-59183\PostInstall\PostInstall\SelectPrograms.vb 40 23 PostInstall
plus what exactly does the code do?
Re: listview - count checked items
It checks or unchecks all items + sets the button text.
Which version of vb are you using + which framework are you targetting?