Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Visual Basic 2005 Basics
|
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
 
Old March 20th, 2009, 06:33 AM
Authorized User
 
Join Date: Nov 2007
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Hughesie78
Default

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
 
Old March 20th, 2009, 08:09 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

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.
================================================== =========
 
Old March 20th, 2009, 09:17 AM
Authorized User
 
Join Date: Nov 2007
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Hughesie78
Default

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
 
Old March 20th, 2009, 09:25 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

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.
================================================== =========
 
Old March 20th, 2009, 09:50 AM
Authorized User
 
Join Date: Nov 2007
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Hughesie78
Default

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
 
Old March 20th, 2009, 09:55 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

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.
================================================== =========
 
Old March 20th, 2009, 10:01 AM
Authorized User
 
Join Date: Nov 2007
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Hughesie78
Default

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
 
Old March 20th, 2009, 01:21 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

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.
================================================== =========
 
Old March 23rd, 2009, 06:50 AM
Authorized User
 
Join Date: Nov 2007
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Hughesie78
Default

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
 
Old March 23rd, 2009, 07:07 AM
Authorized User
 
Join Date: Nov 2007
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Hughesie78
Default

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting all listbox items Lucy_H85 C# 2005 2 December 1st, 2009 05:36 AM
Moving Items up and down in a listbox Brendan Bartley Access 15 September 18th, 2007 06:42 AM
UNSelect Items in ListBox mmcdonal Access VBA 7 June 21st, 2007 08:09 AM
Unhighlight Listbox Items selevanm Access VBA 1 March 7th, 2007 01:39 PM
One item in Listbox venterjo General .NET 2 February 1st, 2005 05:45 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.