Results 1 to 16 of 16

Thread: [RESOLVED] Customized? Select All

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    153

    Resolved [RESOLVED] Customized? Select All

    I have four sets of combo boxes in four separate control arrays. Beside each combo box is a check box also in four separate control arrays. The text boxes and check boxes are in three columns. See image.

    I need a Select all check box that will check all check boxes only if the combo box text next to each one is not null.

    Is a checkbox list array still the best way to handle this or is their a better way? If a check box list is the best way to do this and if it matters I do not intend to make the check box list visible at any point.
    Attached Images Attached Images  
    Last edited by Tesla1886; Jul 14th, 2022 at 01:29 PM.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    24,908

    Re: Customized? Select All

    Loop through you ComboBox array. If each item selectedindex > -1 then check your checkbox via your parallel checkbox array

  3. #3
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,140

    Re: Customized? Select All

    If you are not going to make the check box array visible, what purpose will it serve? What are you going to do with it? If we knew that, we might have some other ideas on a much more simple method to accomplish whatever you are wanting to do.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    153

    Re: Customized? Select All

    Quote Originally Posted by jdc2000 View Post
    If you are not going to make the check box array visible, what purpose will it serve? What are you going to do with it? If we knew that, we might have some other ideas on a much more simple method to accomplish whatever you are wanting to do.
    It is not the array I'd make not visible, it is the checkbox list. If the check box list is not needed for this functionality, I won't need it for any other reason and will delete it.

    I have written a program to add, edit or remove information to an XML file. The information in the combo box may or may not be included from one record to the next. The user will be able to check the select all check box. If the combo box is anything other then null the check box beside it will be checked. As the user goes through the information to include in the current record they can uncheck the checkbox beside the combo box with the correct information. Any check boxes that are still checked when the user saves the recor d the data in the combo box beside it will no be added to the XML file

    I have written code in the SelectAllCheckBox_CheckedChanged that either selects all or deselects all depending on their current status. However I what I am currently having trouble with is other then changing the state of all check boxes at once it does not function as a normal check box, which I would like. So if I uncheck one of the check boxes in the image above, for example the select all button does not uncheck.

    I am sure I can write the functionality I want but it won't be the best way to do this I am sure.

  5. #5
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    33,923

    Re: Customized? Select All

    Quote Originally Posted by Tesla1886 View Post
    I have written code in the SelectAllCheckBox_CheckedChanged that either selects all or deselects all depending on their current status. However I what I am currently having trouble with is other then changing the state of all check boxes at once it does not function as a normal check box, which I would like. So if I uncheck one of the check boxes in the image above, for example the select all button does not uncheck.
    So what code do you have?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    153

    Re: Customized? Select All

    Code:
    If SelectAllCheckBox.Checked = True Then
                For X = 0 To AssProdArrayCB.Length - 1
                    If AssProdArrayCB(X).Text <> "" Then
                        DeleteAssProdArrayCB(X).Checked = True
    
                    End If
    
                Next
    
                For X = 0 To ExProdArrayCB.Length - 1
                    If ExProdArrayCB(X).Text <> "" Then
                        DeleteExprodArrayCB(X).Checked = True
    
                    End If
                Next
    
                For X = 0 To ProdArrayCB.Length - 1
                    If ProdArrayCB(X).Text <> "" Then
                        DeleteProdArrayCB(X).Checked = True
    
                    End If
                Next
    
            Else
                For X = 0 To AssProdArrayCB.Length - 1
                    If AssProdArrayCB(X).Text <> "" Then
                        DeleteAssProdArrayCB(X).Checked = False
    
                    End If
    
                Next
    
                For X = 0 To ExProdArrayCB.Length - 1
                    If ExProdArrayCB(X).Text <> "" Then
                        DeleteExprodArrayCB(X).Checked = False
    
                    End If
                Next
    
                For X = 0 To ProdArrayCB.Length - 1
                    If ProdArrayCB(X).Text <> "" Then
                        DeleteProdArrayCB(X).Checked = False
    
                    End If
                Next
    
            End If

  7. #7
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    24,908

    Re: Customized? Select All

    Those array names could be the butt of someone’s jokes

  8. #8
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    24,908

    Re: Customized? Select All

    To answer your question… If you want to programmatically set your checkboxes checkedstate, then the CheckBox.Checked event is not the place to do that.’

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    153

    Re: Customized? Select All

    Quote Originally Posted by .paul. View Post
    To answer your question… If you want to programmatically set your checkboxes checkedstate, then the CheckBox.Checked event is not the place to do that.’
    No that doesn't answer my question. Not even close

  10. #10
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    24,908

    Re: Customized? Select All

    You want to programmatically set a checkbox based on the selection of a ComboBox??? Use the ComboBox SelectedIndex_Changed event. If you use the CheckBoxes Checked_Changed event, of course your CheckBoxes won’t work.

  11. #11
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    24,908

    Re: Customized? Select All

    If you want one checkbox as a select all checkbox, why don’t you show us ALL of the relevant code?
    I’d set Enabled = false, and only enable the checkbox when ALL of your comboboxes had a valid value.
    Then it’d be a simple loop through your checkboxes array to set all as checked

  12. #12
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    24,908

    Re: Customized? Select All

    If it really is select only those where the ComboBox has a valid value, then I answered your question in post #2

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    153

    Re: Customized? Select All

    Quote Originally Posted by .paul. View Post
    If you want one checkbox as a select all checkbox, why donÂ’t you show us ALL of the relevant code?
    I have posted all the code relevant code that I have for this. I have nothing else.

    Quote Originally Posted by .paul.;5574093I
    I’d set Enabled = false, and only enable the checkbox when ALL of your comboboxes had a valid value.
    Then itÂ’d be a simple loop through your checkboxes array to set all as checked
    I thought about disabling the "unneeded" checkboxes but was not sure that was the most efficent way


    Quote Originally Posted by .paul. View Post
    If it really is select only those where the ComboBox has a valid value, then I answered your question in post #2
    It is not just about select only. I would like to have a fully functional Select All ability In addition to select all / un-select all, but also when one of the check boxes is checked the Select all unchecks. If only one of the check boxes is uncheck and becomes checked then the Select all is checked.

    As an example this is what I want. I just don't know how to do this with the control arrays

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    153

    Re: Customized? Select All

    For those that will find this thread in the future with the same issue. The following is what I did to get the functionality I want, a fully functional "Select All" checkbox where multiple check box arrays are used.

    I created a boolean model array for each of the Checkbox arrays.

    In form load I loaded True into each array.

    I put the following code into the click event for the "Select All" checkbox. This either checks or unchecks all relevant checkboxes, including the "Select All". If the individual checkboxes are disable their check states is not changed in the boolean array
    Code:
    Private Sub SelectAllCheckBox_Click(sender As Object, e As EventArgs) Handles SelectAllCheckBox.Click
            Dim SelectAllCheckBoolean As Boolean = SelectAllCheckBox.Checked
    
            For X = 0 To AssProdArrayCB.Length - 1
                If AssProdArrayCB(X).Text <> "" And DeleteAssProdArrayCB(X).Enabled = True Then
                    DeleteAssProdArrayCB(X).Checked = SelectAllCheckBoolean
                End If
    
            Next X
    
            For X = 0 To ExProdArrayCB.Length - 1
                If ExProdArrayCB(X).Text <> "" And DeleteExprodArrayCB(X).Enabled = True Then
                    DeleteExprodArrayCB(X).Checked = SelectAllCheckBoolean
    
                End If
    
            Next X
    
            For X = 0 To ProdArrayCB.Length - 1
                If ProdArrayCB(X).Text <> "" And DeleteProdArrayCB(X).Enabled = True Then
                    DeleteProdArrayCB(X).Checked = SelectAllCheckBoolean
    
                End If
    
            Next X
    
            SelectAllCheckBox.Checked = SelectAllCheckBoolean
    
        End Sub
    The following Code is in the checkchanged event for each of the individual check boxes. The control array is looped through and if the Combobox is not null checkbox is enabled its checked status is update in the boolean array
    Code:
        Private Sub DeleteAssProdCheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles DeleteAssProdCheckBox1.CheckedChanged
            Dim AssProdBoolean As Boolean = DeleteAssProdCheckBox1.Checked
    
            If AssProComboBox1.Text <> "" And AssProComboBox1.Enabled = True Then
                DeleteAssProdCheckBox1.Checked = AssProdBoolean
    
            End If
    
            AssProdCheck()
    
        End Sub
    The following code is in the sub called by each of the checkboxes. The status of each of the check boxes are updated according to what is in the boolean array
    Code:
        Private Sub AssProdCheck()
            For X = 0 To DeleteAssProdArrayCB.Count - 1
                AssProdCheckedBoolean(X) = DeleteAssProdArrayCB(X).Checked
    
            Next
    
            SelectAllCheck()
    
        End Sub
    Finally the code below determines whether or not each of the individual check boxes are checked and then checks or unchecks the "Select All" checkbox accordingly.
    Code:
        Private Sub SelectAllCheck()
            If AssProdCheckedBoolean.All(predicate:=Function(ue) ue = True) And
              ExProdCheckedBoolean.All(predicate:=Function(ue) ue = True) And
              ProdCheckedBoolean.All(predicate:=Function(ue) ue = True) Then
                SelectAllCheckBox.Checked = True
    
            Else
                SelectAllCheckBox.Checked = False
    
            End If
    
        End Sub
    This may not have been the most efficient way to do this, but it works and I see no change in how my program runs

  15. #15
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    108,871

    Re: [RESOLVED] Customized? Select All

    Firstly, you don't handle the Click event of a CheckBox. That is almost certainly irrelevant. You should be handling the CheckedChanged event. What if the user checks the box using the keyboard?

    Secondly, if you want a one to one correspondence between ComboBoxes and CheckBoxes then use a Dictionary(Of ComboBox, CheckBox). When the special CheckBox is checked, you can run through the Dictionary and check each CheckBox based on the state of its corresponding ComboBox. That might look like this:
    vb.net Code:
    1. Private checkBoxesByComboBox As Dictionary(Of ComboBox, CheckBox)
    2.  
    3. Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Form1.Load
    4.     checkBoxesByComboBox = New Dictionary(Of ComboBox, CheckBox) {{ComboBox1, CheckBox1}, {ComboBox2, CheckBox2}}
    5. End Sub
    6.  
    7. Private Sub checkAllBox_CheckedChanged(sender As Object, e As EventArgs) Handles Form1.Load
    8.     Dim checkAll = checkAllBox.Checked
    9.  
    10.     For Each kvp In checkBoxesByComboBox
    11.         If kvp.Key.SelectedItem IsNot Nothing AndAlso kvp.Value.Enabled Then
    12.             kvp.Value.Checked = checkAll
    13.         End If
    14.     Next
    15. End Sub

  16. #16
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    2,912

    Re: [RESOLVED] Customized? Select All

    JMC beat me, well I will post anyway

    Code:
    Public Class Form2
    
    
        Private Sub WireUpCheckboxesWithControls()
            Dim kvps = New Dictionary(Of CheckBox, Control) From {{CheckBox1, ComboBox1}, _
                                                                 {CheckBox2, ComboBox2}, _
                                                                 {CheckBox3, ComboBox3}}
            For Each kvp In kvps
                kvp.Value.Enabled = kvp.Key.Checked
                kvp.Value.DataBindings.Add("Enabled", kvp.Key, "Checked", False, DataSourceUpdateMode.OnPropertyChanged)
            Next
        End Sub
    
        Private Sub Form2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            WireUpCheckboxesWithControls()
        End Sub
    End Class
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width