CheckedListBox on Tab Control

I've got another strange problem with the CheckedListBox control which I have showing on a Tab Control. When I check a few items, switch it another tab and switch back the CheckedListBox has reset itself and lost the selections I made.

Isn't the CheckedListBox supported within the Tab Control? Or....?
PeterErhardAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

davidrichardsonCommented:
if the are bound controles try updating the dataset before switching to another tab
0
PeterErhardAuthor Commented:
Thanks for your response David.

Problem being is that if the user selects a few options on the CheckedListBox I don't want to save until these options to the database until the save button is clicked. Is there anyway around that?
0
PeterErhardAuthor Commented:
Anyone?
0
davidrichardsonCommented:
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PeterErhardAuthor Commented:
Thanks for that - turns out it's a bug with VB.net - not fixed in the service pack either.

I've got it working with this but now it turns out my saving and loading isn't working because I'm no longer using a dataset.

    Private Function LoadEthnicGroups() As Boolean

        Dim cmd As SqlCommand = cnn.CreateCommand
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "procLoadEthnicGroupOptions"

        Dim reader As SqlDataReader = cmd.ExecuteReader

        While reader.Read
            With reader
                ListBox_EthnicGroup.Items.Add(.GetValue(.GetOrdinal("EthnicGroup")))
                ListBox_EthnicGroup.Items.IndexOf(.GetValue(.GetOrdinal("LookUp_EthnicGroupIDAuto")))
            End With
        End While

        reader.Close()

        LoadEthnicGroups = True

    End Function

I can't believe what a pain in the arse this CheckedListBox control is. Do you know what I can replace this line of the code with - ItemIndex = CType(ListBox_EthnicGroup.Items(Count), DataRowView)("LookUp_EthnicGroupIDAuto") ?

    Private Function LoadClientEthnicGroup() As Boolean

        Dim EthnicGroupCount As Integer, EthnicGroupIDAuto As Integer
        Dim ItemIndex As Object, Count As Integer

        Try
            'Get Number of Ethnic Group Items in ListBox
            EthnicGroupCount = ListBox_EthnicGroup.Items.Count()

            Dim cmd As SqlCommand = cnn.CreateCommand
            cmd.CommandType = CommandType.StoredProcedure
            cmd.CommandText = "procLoadClientEthnicGroupOptions"

            cmd.Parameters.Add(New SqlParameter("@ClientIDAuto", SqlDbType.Int, 4))
            cmd.Parameters("@ClientIDAuto").Value = 1

            Dim dr As SqlDataReader = cmd.ExecuteReader

            While dr.Read
                With dr
                    EthnicGroupIDAuto = CInt(.GetValue(.GetOrdinal("EthnicGroupIDAuto")))

                    'Find out the Index for the EthnicGroupIDAuto Saved
                    'And check the item
                    For Count = 0 To EthnicGroupCount - 1
                        'ItemIndex = CType(ListBox_EthnicGroup.Items(Count), DataRowView)("LookUp_EthnicGroupIDAuto")
                        'ItemIndex = CType(ListBox_EthnicGroup.Items(Count), CheckedListBox.SelectedIndexCollection)
                        'ItemIndex = CType(ListBox_EthnicGroup.Items(Count), CheckedListBox.SelectedIndexCollection)
                        If CInt(EthnicGroupIDAuto) = CInt(ItemIndex) Then
                            ListBox_EthnicGroup.SetItemChecked(Count, True)
                        End If
                    Next
                End With
            End While
            dr.Close()

            LoadClientEthnicGroup = True

        Catch ex As Exception
            MessageBox.Show(Err.Description)
        End Try
    End Function

and the same here:

    Private Function SaveClientEthnicGroup() As Boolean()
        Try
            Dim Index As Integer

            Dim cmdDelete As New Data.SqlClient.SqlCommand("Delete from ClientIDAuto_EthnicGroupIDAuto where ClientIDAuto = " & m_ClientNumber, cnn)
            cmdDelete.ExecuteNonQuery()

            Dim cmdInsert As New Data.SqlClient.SqlCommand("Insert into ClientIDAuto_EthnicGroupIDAuto (ClientIDAuto, EthnicGroupIDAuto) Values (@ClientIDAuto, @EthnicGroupIDAuto)", cnn)
            cmdInsert.Parameters.Add("@ClientIDAuto", m_ClientNumber)
            cmdInsert.Parameters.Add("@EthnicGroupIDAuto", SqlDbType.Int)

            For Each Index In ListBox_EthnicGroup.CheckedIndices
                cmdInsert.Parameters("@EthnicGroupIDAuto").Value = CType(ListBox_EthnicGroup.Items(Index), DataRowView)("LookUp_EthnicGroupIDAuto")
                cmdInsert.ExecuteNonQuery()
            Next
        Catch ex As Exception
            MessageBox.Show(Err.Description)
        End Try
    End Function
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.