 |
| Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book:
Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Visual Basic 2005 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

March 20th, 2009, 06:33 AM
|
|
Authorized User
|
|
Join Date: Nov 2007
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
ok, here is what ive done. now, it works fine, until i select 3 from items 1-9, and want to select back to item 0, its not setting my boolean to true.
Dim bStore As Boolean
bStore = False
'determine what has been selected and give it boolean
If lstStore.Items.Count >= 0 Then
For i = 0 To lstStore.Items.Count - 1
If bStore = True And lstStore.GetSelected(i) = True And i <> 0 Then
bStore = False
ElseIf bStore = True And lstStore.GetSelected(i) = True And i = 0 Then
bStore = True
ElseIf bStore = False Then
If lstStore.GetSelected(i) = True And i = 0 Then
bStore = True
ElseIf lstStore.GetSelected(i) = True And lstStore.GetSelected(0) = True Then
bStore = True
ElseIf lstStore.GetSelected(i) = True And lstStore.GetSelected(0) = True And i <> 0 Then
bStore = True
End If
Else
bStore = True
End If
Next i
'pass stores based on boolena bStore
If bStore = True Then
Me.lstStore.ClearSelected()
Me.lstStore.SetSelected(0, True)
Else
Me.lstStore.SetSelected(0, False)
End If
End If
__________________
Thank You
|
|

March 20th, 2009, 08:09 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
Bstore has to be at form level, not procedure level. nothing is good if you have it that way (since it will always take the value of item 0 selection, so you are not winning anything). The whole idea, is to know if the item was previously selected, or was selected in this change.
Also did you read the rest of the post?? you are still making the errors I pointed to you.
__________________
HTH
Gonzalo
================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the proof.
================================================== =========
|
|

March 20th, 2009, 09:17 AM
|
|
Authorized User
|
|
Join Date: Nov 2007
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
hi
yes I read the rest of your post, I will make those changes, but first.. what can i do to make hte bstore at form level.. if u didnt guess already.. am Im a VB.net newbie!
__________________
Thank You
|
|

March 20th, 2009, 09:25 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
Well, if you can define a variable at procedure level, you can do it the same at form level (in this case, your form is a class). Just take it outside the procedure.. and read!, google is your best friend.
__________________
HTH
Gonzalo
================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the proof.
================================================== =========
|
|

March 20th, 2009, 09:50 AM
|
|
Authorized User
|
|
Join Date: Nov 2007
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
ok.. have declared bStore now outside my onlclick 'PrivateSub lstStore_Click
still when i select any of 1-9 items, i cannot reslect item 0.
__________________
Thank You
|
|

March 20th, 2009, 09:55 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
mmm.. And did you change your code????
read my pseudo code and try to make it work. Your actual code don't work (not even do what is supposed to do. Why not try with adding some comments so you find out if you are doing what you are supposed to do. Also, debugging is a great way to find out what is happening.
Are you new to programming also?
__________________
HTH
Gonzalo
================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the proof.
================================================== =========
|
|

March 20th, 2009, 10:01 AM
|
|
Authorized User
|
|
Join Date: Nov 2007
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
no didnt change. not sure exactly what to do.
I wouldnt say new, raw & new to OO would be more the truth, im a DB Developer.
__________________
Thank You
|
|

March 20th, 2009, 01:21 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
ok. This will do the trick, put a checkedlistbox on a form and add this...
Code:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'add info to the listbox
For i As Int16 = 0 To 9
Me.CheckedListBox1.Items.Add(i, False)
Next
End Sub
Private Sub CheckedListBox1_ItemCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles CheckedListBox1.ItemCheck
If e.Index = 0 Then
'has changed the first element
If e.NewValue = CheckState.Checked Then
'clear the rest of the list
While CheckedListBox1.CheckedIndices.Count > 0
CheckedListBox1.SetItemCheckState(CheckedListBox1.CheckedIndices.Item(0), CheckState.Unchecked)
End While
End If
Else
'has changed the other elements
'don't do anything
End If
End Sub
__________________
HTH
Gonzalo
================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the proof.
================================================== =========
|
|

March 23rd, 2009, 06:50 AM
|
|
Authorized User
|
|
Join Date: Nov 2007
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
thanks a mil.
is there anyway this can be done by using only a list box, and not a checked list box? list box is the preffered choice.
__________________
Thank You
|
|

March 23rd, 2009, 07:07 AM
|
|
Authorized User
|
|
Join Date: Nov 2007
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
also, when I use the code above, and i sected two Items between 1 & 9 i get a break error "An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll"
__________________
Thank You
|
|
 |