Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old July 28th, 2006, 10:25 AM
whitelm whitelm is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Posts: 13 whitelm User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 32 m 18 sec
Reputation Power: 0
Smile Checkbox

I'm having trouble allowing the checkbox to be unchecked. I have several checkboxs to allow the user to select items, that appear in a textbox. If the change their minds and want to uncheck the box, I need to remove that item in the textbox. I found a work around but its not elegant. I added an additional checkbox to clear all choices and resetting all checkboxes to unchecked state. I disable the checkbox to prevent unchecking.


I think the users would prefer to check or uncheck the individual boxes. Any assistance on this would be greatly appreciated.

Current code for 1 of the checkboxs:

Private Sub cbGrilledPeppers_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbGrilledPeppers.CheckedChanged
tbCondiments.Text = tbCondiments.Text & "> " & "Grilled Peppers"
If cbGrilledPeppers.CheckState = CheckState.Checked Then
' If checked, do not allow items to be dragged onto the form.
Me.cbGrilledPeppers.Enabled = False
End If
End Sub


Thank you

Reply With Quote
  #2  
Old August 1st, 2006, 08:03 AM
sync_or_swim's Avatar
sync_or_swim sync_or_swim is offline
Moderator
Click here for more information.
 
Join Date: Mar 2006
Location: South Wales
Posts: 1,932 sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 6 Days 22 h 33 m 54 sec
Reputation Power: 1243
Hi Whiteelm,

Sorry if this is a bit cumbersome, but I just threw this together to demonstrate one way to achieve this using an array of items and simply deleting/adding the items from/to the array. You can then display the contents of the array in the textbox.

To a Form (Form1) add three checkboxes: chkPickles, chkCheese & chkCucumber and one textbox: Text1.

Now add the following code:
Code:
Option Explicit
'Define an array of n-1 elements, where n is the number of checkboxes
Dim strItems(2) As String
Dim a As Integer
Dim intpos As Integer
Dim intBlank As Integer
Dim found As Boolean

Private Sub chkCheese_Click()
If chkCheese.Value = 1 Then
    For a = 0 To UBound(strItems)
        If strItems(a) = "Cheese" Then
            found = True
            intpos = a
        Else
            If strItems(a) = "X" Then
                intBlank = a
            End If
        End If
    Next
    If found <> True Then
        strItems(intBlank) = "Cheese"
    End If
Else
    For a = 0 To UBound(strItems)
        If strItems(a) = "Cheese" Then strItems(a) = "X"
    Next
End If
Text1.Text = ""
For a = 0 To UBound(strItems)
    If strItems(a) <> "X" Then Text1.Text = Text1.Text & strItems(a) & " "
Next
found = False
End Sub

Private Sub chkCucumber_Click()
If chkCucumber.Value = 1 Then
    For a = 0 To UBound(strItems)
        If strItems(a) = "Cucumber" Then
            found = True
            intpos = a
        Else
            If strItems(a) = "X" Then
                intBlank = a
            End If
        End If
    Next
    If found <> True Then
        strItems(intBlank) = "Cucumber"
    End If
Else
    For a = 0 To UBound(strItems)
        If strItems(a) = "Cucumber" Then strItems(a) = "X"
    Next
End If
Text1.Text = ""
For a = 0 To UBound(strItems)
    If strItems(a) <> "X" Then Text1.Text = Text1.Text & strItems(a) & " "
Next
found = False
End Sub

Private Sub chkPickles_Click()
If chkPickles.Value = 1 Then
    For a = 0 To UBound(strItems)
        If strItems(a) = "Pickles" Then
            found = True
            intpos = a
        Else
            If strItems(a) = "X" Then
                intBlank = a
            End If
        End If
    Next
    If found <> True Then
        strItems(intBlank) = "Pickles"
    End If
Else
    For a = 0 To UBound(strItems)
        If strItems(a) = "Pickles" Then strItems(a) = "X"
    Next
End If
Text1.Text = ""
For a = 0 To UBound(strItems)
    If strItems(a) <> "X" Then Text1.Text = Text1.Text & strItems(a) & " "
Next
found = False
End Sub

Private Sub Form_Load()
found = False
For a = 0 To UBound(strItems)
strItems(a) = "X"
Next
End Sub

Hopefully this will give you some ideas,

Rob

Reply With Quote
  #3  
Old August 1st, 2006, 08:40 AM
sync_or_swim's Avatar
sync_or_swim sync_or_swim is offline
Moderator
Click here for more information.
 
Join Date: Mar 2006
Location: South Wales
Posts: 1,932 sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 6 Days 22 h 33 m 54 sec
Reputation Power: 1243
To make it a little bit more readable you can make the items appear on different lines of the textbox by setting it's multiline property to True, you can now change the line of code at the end of each checkboxes Click event to add a Carriage Return Line Feed character to the line:
Code:
Private Sub chkCheese_Click()
If chkCheese.Value = 1 Then
    For a = 0 To UBound(strItems)
        If strItems(a) = "Cheese" Then
            found = True
            intpos = a
        Else
            If strItems(a) = "X" Then
                intBlank = a
            End If
        End If
    Next
    If found <> True Then
        strItems(intBlank) = "Cheese"
    End If
Else
    For a = 0 To UBound(strItems)
        If strItems(a) = "Cheese" Then strItems(a) = "X"
    Next
End If
Text1.Text = ""
For a = 0 To UBound(strItems)
    If strItems(a) <> "X" Then Text1.Text = Text1.Text & strItems(a) & vbCrLf
Next
found = False
End Sub
etc..

Reply With Quote
  #4  
Old August 2nd, 2006, 10:32 AM
whitelm whitelm is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Posts: 13 whitelm User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 32 m 18 sec
Reputation Power: 0
Cool Checkbox

Thank you for the quick reply. I will try your code today. I will post the final code after testing. Appreciate the assistance.

Larry

Quote:
Originally Posted by sync_or_swim
To make it a little bit more readable you can make the items appear on different lines of the textbox by setting it's multiline property to True, you can now change the line of code at the end of each checkboxes Click event to add a Carriage Return Line Feed character to the line:
Code:
Private Sub chkCheese_Click()
If chkCheese.Value = 1 Then
    For a = 0 To UBound(strItems)
        If strItems(a) = "Cheese" Then
            found = True
            intpos = a
        Else
            If strItems(a) = "X" Then
                intBlank = a
            End If
        End If
    Next
    If found <> True Then
        strItems(intBlank) = "Cheese"
    End If
Else
    For a = 0 To UBound(strItems)
        If strItems(a) = "Cheese" Then strItems(a) = "X"
    Next
End If
Text1.Text = ""
For a = 0 To UBound(strItems)
    If strItems(a) <> "X" Then Text1.Text = Text1.Text & strItems(a) & vbCrLf
Next
found = False
End Sub
etc..

Reply With Quote
  #5  
Old August 2nd, 2006, 11:37 AM
whitelm whitelm is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Posts: 13 whitelm User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 32 m 18 sec
Reputation Power: 0
Smile Checkbox

Thank you for your assistance. It got me thinking. I re-wrote my code as follows to provide me the required text as each checkbox is checked. Each checkbox has its own textbox, then I combine the results of all textbox entries for a single text string for the database field:

Private Sub cbGrilledOnions_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbGrilledOnions.CheckedChanged
tbGrilledOnions.Text = "Grilled Onions"
If cbGrilledOnions.CheckState = CheckState.Checked Then
' If checked, do not allow items to be dragged onto the form.
'Me.cbGrilledOnions.Enabled = False
ElseIf cbGrilledOnions.CheckState = CheckState.Unchecked Then
tbGrilledOnions.Text = " "
End If
End Sub



Quote:
Originally Posted by sync_or_swim
To make it a little bit more readable you can make the items appear on different lines of the textbox by setting it's multiline property to True, you can now change the line of code at the end of each checkboxes Click event to add a Carriage Return Line Feed character to the line:
Code:
Private Sub chkCheese_Click()
If chkCheese.Value = 1 Then
    For a = 0 To UBound(strItems)
        If strItems(a) = "Cheese" Then
            found = True
            intpos = a
        Else
            If strItems(a) = "X" Then
                intBlank = a
            End If
        End If
    Next
    If found <> True Then
        strItems(intBlank) = "Cheese"
    End If
Else
    For a = 0 To UBound(strItems)
        If strItems(a) = "Cheese" Then strItems(a) = "X"
    Next
End If
Text1.Text = ""
For a = 0 To UBound(strItems)
    If strItems(a) <> "X" Then Text1.Text = Text1.Text & strItems(a) & vbCrLf
Next
found = False
End Sub
etc..

Reply With Quote
  #6  
Old August 2nd, 2006, 11:49 AM
sync_or_swim's Avatar
sync_or_swim sync_or_swim is offline
Moderator
Click here for more information.
 
Join Date: Mar 2006
Location: South Wales
Posts: 1,932 sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 6 Days 22 h 33 m 54 sec
Reputation Power: 1243
Larry,

I'm glad you've figured it out, it makes a lot of sense doing it that way, just concatenating the contents of all the textboxes!! Sorry if mine was a bit of a long winded way of going about it, at least it gave you some inspiration though!!

Regards,

Rob

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Checkbox


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT