|
-
May 20th, 2003, 02:04 PM
#1
Thread Starter
Addicted Member
Here's a stupid question!
I have a checked list box that has 10 values in it.
I want to create a button that selects (or deselects) all of them at once. I am assuming I have to do a:
For Each strItems in ListBox1.Items
Next
But what is the syntax to check a box?
Thanks in advance,
Jim
-
May 20th, 2003, 02:24 PM
#2
Thread Starter
Addicted Member
Resolved but I am sure there is an easier way than this...
VB Code:
Dim intCount As Integer
Dim x As Integer = 0
For intCount = 0 To lbDriversVer2.Items.Count.ToString - 1
lbDriversVer2.SetItemChecked(x, True)
x = x + 1
Next
-
May 20th, 2003, 02:27 PM
#3
Frenzied Member
Hey man, look at your code. It can be done in this way, i guess better syntax
VB Code:
Dim intCount As Integer
For intCount = 0 To lbDriversVer2.Items.Count- 1
lbDriversVer2.SetItemChecked(intCount, True)
Next
There are some technical problems in your code, if already dont know them i will tell you.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
May 20th, 2003, 03:20 PM
#4
Sleep mode
Originally posted by jlegan
VB Code:
For intCount = 0 To lbDriversVer2.Items.Count.ToString - 1
This may work but , it doesn't make sense . Why did you convert count property to string ?. Just wonder !
-
May 20th, 2003, 03:26 PM
#5
Frenzied Member
That was one of technical problems i was talking about
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
May 20th, 2003, 03:30 PM
#6
Sleep mode
Originally posted by Lunatic3
That was one of technical problems i was talking about
lol ..One of them ? I can't see anything else wrong ! right ?
-
May 20th, 2003, 03:33 PM
#7
Frenzied Member
Isn't defining:
Dim x As Integer = 0
and using that a poor technique?
Last edited by Lunatic3; May 20th, 2003 at 03:59 PM.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
May 20th, 2003, 03:36 PM
#8
Thread Starter
Addicted Member
Ok, follow-up question:
This works
VB Code:
Dim intCount As Integer
For intCount = 0 To lbDriversVer2.Items.Count- 1
lbDriversVer2.SetItemChecked(intCount, True)
Next
Now if I add the funtionality to make to check or uncheck all of them when I click on it it checks all of them however when I uncheck it nothing happens (it doesn't seem to process it again and take the Else route):
VB Code:
Private Sub chkVer2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkVer2.CheckedChanged
Dim intCount As Integer
If chkVer2.CheckState.Checked Then
For intCount = 0 To lbDriversVer2.Items.Count - 1
lbDriversVer2.SetItemChecked(intCount, True)
Next
Else
For intCount = 0 To lbDriversVer2.Items.Count - 1
lbDriversVer2.SetItemChecked(intCount, False)
Next
End If
End Sub
Any thoughts as to why?
Last edited by jlegan; May 20th, 2003 at 04:10 PM.
-
May 20th, 2003, 03:41 PM
#9
Sleep mode
Originally posted by Lunatic3
Isnt defining:
Dim x As Integer = 0
and using that a poor technique.
No way , you kidding , why it's poor tech ?
-
May 20th, 2003, 03:49 PM
#10
Thread Starter
Addicted Member
LOL I sure am glad that everyone here encourages learning seeing as I have just finished writting my first application from scratch and I have to deal with ppl making fun of the syntax I used when trying to figure something out.
-
May 20th, 2003, 04:02 PM
#11
Frenzied Member
No way , you kidding , why it's poor tech ?
Are you making fun of me?
That Dim... per se is not a poor technique, but in his code it was not needed at all. (this is for jlegan)
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
May 20th, 2003, 04:05 PM
#12
Thread Starter
Addicted Member
Lun,
In proper technique and form do you know the answer to about 3 posts ago about toggling it back and forth?
-
May 20th, 2003, 04:09 PM
#13
Frenzied Member
doesn't seem to process it again and take the Else route):
So check your If statment, it may always return true.
If chkVer2 is a checkbox then you may use:
VB Code:
Dim intCount As Integer
For intCount = 0 To lbDriversVer2.Items.Count- 1
lbDriversVer2.SetItemChecked(intCount, chkVer2.Checked)
Next
You dont need any if Statment, and that code goes in cchkVer2_CheckedChanged method.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
May 20th, 2003, 04:10 PM
#14
Sleep mode
-
May 20th, 2003, 04:11 PM
#15
Frenzied Member
Pirate! for Gods sake tell me if he needed to use X in his original code or not
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
May 20th, 2003, 04:14 PM
#16
Sleep mode
Originally posted by Lunatic3
Pirate! for Gods sake tell me if he needed to use X in his original code or not
What's X you are talking about ? interger = 0 ??
-
May 20th, 2003, 04:16 PM
#17
Frenzied Member
Yes, and it subsequent use in the code above
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
May 20th, 2003, 04:16 PM
#18
Sleep mode
Originally posted by jlegan
Resolved but I am sure there is an easier way than this...
VB Code:
Dim intCount As Integer
Dim x As Integer = 0
For intCount = 0 To lbDriversVer2.Items.Count.ToString - 1
lbDriversVer2.SetItemChecked(x, True)
x = x + 1
Next
Uh..Well , yes , absolutely no need to use it . right Lunatic3
-
May 20th, 2003, 04:17 PM
#19
Thread Starter
Addicted Member
Can someone please just tell me why this will check all of the boxes in the checked list box when checked but will not uncheck them when it gets unchecked?
VB Code:
Private Sub chkVer2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkVer2.CheckedChanged
Dim intCount As Integer
If chkVer2.CheckState.Checked Then
For intCount = 0 To lbDriversVer2.Items.Count - 1
lbDriversVer2.SetItemChecked(intCount, True)
Next
Else
For intCount = 0 To lbDriversVer2.Items.Count - 1
lbDriversVer2.SetItemChecked(intCount, False)
Next
End If
End Sub
-
May 20th, 2003, 04:19 PM
#20
Sleep mode
What is "chkVer2" , I couldn't figure it out !
-
May 20th, 2003, 04:20 PM
#21
Thread Starter
Addicted Member
chkVer2 is a single checkbox
lbDriversVer2 is a Checked List Box
-
May 20th, 2003, 04:24 PM
#22
Thread Starter
Addicted Member
I also changed the Event Handler to .CheckStateChanged but that didn't make a difference either.
-
May 20th, 2003, 04:26 PM
#23
Frenzied Member
The code i sent you 9 posts before this was useless????
by the way you should use:
chkVer2.CheckState=CheckState.Checked
Last edited by Lunatic3; May 20th, 2003 at 04:29 PM.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
May 20th, 2003, 04:29 PM
#24
Thread Starter
Addicted Member
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
|