Click here to Skip to main content
15,038,237 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 «system.data.datarowview» 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.
VB
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
        Else
            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"
        Else
            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
        Me.Close()
    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")
            Me.Close()
        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(item)
            sb.Append(" ")
        Next
        MessageBox.Show(sb.ToString())
'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")
        Else
            Try
                UcctieDataSet.impressoras.NewimpressorasRow()
                Me.ImpressorasTableAdapter.Insert(texto, maquinas)
                Me.UcctieDataSet.impressoras.AcceptChanges()
                Me.ImpressorasTableAdapter.Update(Me.UcctieDataSet.impressoras)

                MsgBox("Impressora da Maquina " + maquinas + " adicionada com êxito")
                Me.Close()
            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
Posted
Updated 16-Dec-14 23:34pm
v2

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