Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you clear (repopulate) a checkedlistbox 2

Status
Not open for further replies.

basbrian

Programmer
Feb 18, 2002
49
AU
I have a form that has 2 combo boxes and a checkedlistbox. Combo1 contains a position number,combo 2 contains positions. When the user selects a pos no it populates combo2 with the pos desc and then lists responsibilites for that position in the checkedlistbox. When I select another pos no or pos desc i want to clear the checkedlistbox and repopulate it with the responsibilities of the new pos. Everything i have tried has resulted in an error.

Any suggestions please, as i am very new at this I am probably doing something majorally wrong.

Code:
 Private Sub CboPosDesc_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CboPosDesc.SelectedIndexChanged
        If CboPosDesc.DisplayMember = "jobname" Then
            If CboPosDesc.ValueMember = "post_ref" Then
                If CboPosDesc.SelectedValue > 0 Then
                    CboPosition.SelectedValue = CboPosDesc.SelectedValue
                    filldelegations()
                End If
            End If
        End If
    End Sub
   
    Private Sub filldelegations()
        Dim strPost As String = CboPosition.Text
        Dim cnposdel As New SqlConnection(connectionString)
        Dim ssqlposdel As String = "SELECT DISTINCT t1.del_code, t1.del_code + ' ' + descript as xdesc FROM coffsdelegation_position t1 join coffsdelegation_type t2 on t1.del_code = t2.del_code where pos_ref = '" & strPost & "'"
        Dim daptposdel As New SqlDataAdapter(ssqlposdel, cnposdel)

        cnposdel.Open()
        daptposdel.Fill(dsposdel, "jobpost")
        fillCLBPosDel()
        CLBPosDel.SelectedIndex = -1

        If cnposdel.State = 1 Then cnposdel.Close()
        cnposdel = Nothing
        dsposdel.Dispose()
        daptposdel.Dispose()
    End Sub
    Private Sub fillCLBPosDel()
        CLBPosDel.DataSource = dsposdel.Tables("jobpost").DefaultView
        CLBPosDel.DisplayMember = "xdesc"
        CLBPosDel.ValueMember = "del_code"
    End Sub
    Private Sub CLBDelegations_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CLBDelegations.SelectedIndexChanged

    End Sub
 
First, I don't do a lot of Binding so this may not be the "best" way. Second, I have to assume that CLBPosDel if your CheckedListBox? If so since it is bound you can't do anything to it till it is unbound. So one way you can do this at least is to set the CLBPosDel.DataSource = Nothing.

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
You're not rebinding after fillCLBPosDel
--> CLBPosDel.Databind()
 
Thanks for the advice.
This has fixed my problem but I am going to look at your suggestions after the new year.

dsposdel.Tables("jobpost").Clear()
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top