none
Mudar cor da linha em um ListView

    Question

  • Bom dia, como faço para alterar a cor de uma única linha em um ListView

    Obrigado,


    • Edited by Elmo2901 Thursday, March 01, 2012 12:37 PM
    Thursday, March 01, 2012 12:30 PM

Answers

  • Consegui alterar a cor da letra de um ListView. Veja o código abaixo:

    Sub Lista_Dados_Mercadorias()
            Dim NewListas As New ListViewItem
            Dim dr_Merca As MySqlDataReader
            Dim Con_Merca As New MySqlConnection(StrMercad)
            Dim Cmd_Merca As New MySqlCommand(Str_Merca, Con_Merca)
            Con_Merca.Open()
            dr_Merca = Cmd_Merca.ExecuteReader
            If dr_Merca.HasRows Then
                ListView1.Items.Clear()
                ListView1.View = View.Details
                ListView1.FullRowSelect = True
                ListView1.SmallImageList = ImageList1
                While dr_Merca.Read
                    If dr_Merca.Item("Status_Merca").ToString = "V" Then
                        NewListas = ListView1.Items.Add(dr_Merca.Item("GrupoMer_Merca").ToString, 0)
                    Else
                        NewListas = ListView1.Items.Add(dr_Merca.Item("GrupoMer_Merca").ToString, 1)
                    End If
                    NewListas.SubItems.Add(dr_Merca.Item("Matricula_Merca").ToString)
                    NewListas.SubItems.Add(dr_Merca.Item("Descricao_Merca").ToString)
                    If dr_Merca.Item("Status_Merca").ToString = "V" Then
                        NewListas.SubItems.Add("ATIVO")
                    Else
                        NewListas.SubItems.Add(dr_Merca.Item("User_Work").ToString)
                        NewListas.ForeColor = Red
                    End If
                End While
            End If
            dr_Merca.Close()
        End Sub

    Assim a cor da(s) letras são alteradas para VERMELHO.

    • Marked as answer by Elmo2901 Thursday, March 01, 2012 1:08 PM
    Thursday, March 01, 2012 1:08 PM

All replies

  • Consegui alterar a cor da letra de um ListView. Veja o código abaixo:

    Sub Lista_Dados_Mercadorias()
            Dim NewListas As New ListViewItem
            Dim dr_Merca As MySqlDataReader
            Dim Con_Merca As New MySqlConnection(StrMercad)
            Dim Cmd_Merca As New MySqlCommand(Str_Merca, Con_Merca)
            Con_Merca.Open()
            dr_Merca = Cmd_Merca.ExecuteReader
            If dr_Merca.HasRows Then
                ListView1.Items.Clear()
                ListView1.View = View.Details
                ListView1.FullRowSelect = True
                ListView1.SmallImageList = ImageList1
                While dr_Merca.Read
                    If dr_Merca.Item("Status_Merca").ToString = "V" Then
                        NewListas = ListView1.Items.Add(dr_Merca.Item("GrupoMer_Merca").ToString, 0)
                    Else
                        NewListas = ListView1.Items.Add(dr_Merca.Item("GrupoMer_Merca").ToString, 1)
                    End If
                    NewListas.SubItems.Add(dr_Merca.Item("Matricula_Merca").ToString)
                    NewListas.SubItems.Add(dr_Merca.Item("Descricao_Merca").ToString)
                    If dr_Merca.Item("Status_Merca").ToString = "V" Then
                        NewListas.SubItems.Add("ATIVO")
                    Else
                        NewListas.SubItems.Add(dr_Merca.Item("User_Work").ToString)
                        NewListas.ForeColor = Red
                    End If
                End While
            End If
            dr_Merca.Close()
        End Sub

    Assim a cor da(s) letras são alteradas para VERMELHO.

    • Marked as answer by Elmo2901 Thursday, March 01, 2012 1:08 PM
    Thursday, March 01, 2012 1:08 PM
  • Boa tarde Elmo2901,

    Veja se ajuda!

    Private Sub Colorir_ListView(ByVal LV As ListView)

            Dim i As Integer = 0

            While i < LV.Items.Count

                If LV.Items(i).Text = "<textodalinhadolistview>" Then

                    LV.Items(i).BackColor = Color.Red

                End If

                i += 1

            End While

        End Sub

    __________________________________________

    J. Wilson

    Thursday, March 01, 2012 9:03 PM