Click here to Skip to main content
15,850,103 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, i'm having trouble with a routine, using checked list box. The items on the control(checkedlistbox) are added from a database, and all works well, but when i select one of those items from removal, and round a simple control like msgbox, the selections disapears and the text of the item changes to «» the code is the following. the main objective is to remove the selected item, a printer on this case, from the database. The routine to removal is on button3.
Public Class impressoraspredefenidas
    Public maquinas As String
    Private Sub impressoraspredefenidas_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'UcctieDataSet.impressoras' table. You can move, or remove it, as needed.
        If Form1.frm = False Then
            maquinas = Form1.Label30.Text
            maquinas = Detalhes_da_Maquina.Label6.Text
        End If
        Me.ImpressorasTableAdapter.impressora(Me.UcctieDataSet.impressoras, maquinas)
        Label2.Text = "Impressoras Associadas a Maquina " + maquinas
        If Me.UcctieDataSet.impressoras.Rows.Count > 0 Then
            Me.CheckedListBox1.DataSource = Me.UcctieDataSet.impressoras
            Me.CheckedListBox1.DisplayMember = "Impressora"
            Me.CheckedListBox1.ValueMember = "impressora"
            Me.CheckedListBox1.Items.Add("Sem Impressoras Associadas a Maquina " + maquinas)

        End If
        ComboBox1.SelectedIndex = 0

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        Me.ImpressorasTableAdapter.impressora(Me.UcctieDataSet.impressoras, maquinas)
        Dim cnt As Integer
        cnt = Me.UcctieDataSet.impressoras.Count
        If cnt <= 0 Then
            MsgBox("Não existem impressoras associadas a esta Maquina")
        End If
        If CheckedListBox1.CheckedItems.Count = 1 Then
            MsgBox("Não existem Impressoras selecionadas para remoção")
        End If
        Dim sb As New System.Text.StringBuilder
        For Each item In CheckedListBox1.CheckedItems
            sb.Append(" ")
'the code is not complete, because of the problem above

    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim texto As String
        texto = TextBox1.Text + ComboBox1.Text
        If texto = "" Then
            MsgBox("Por favor introduza marca/modelo da impressora e tipo de ligação")
                Me.ImpressorasTableAdapter.Insert(texto, maquinas)

                MsgBox("Impressora da Maquina " + maquinas + " adicionada com êxito")
            Catch ex As Exception
                MsgBox("Erro ao associar a impressora a maquina " + maquinas + ", por favor Corrija", MsgBoxStyle.Critical)
            End Try
        End If
    End Sub

    Private Sub Label2_Click(sender As Object, e As EventArgs) Handles Label2.Click

    End Sub

    Private Sub CheckedListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles CheckedListBox1.SelectedIndexChanged

    End Sub
End Class
Updated 17-Dec-14 0:34am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900