Duplicando colunas no Listview
Enviado: 18 Mar 2016 às 16:17
Senhores, boa tarde. Mais uma vez venho solicitar ajuda do fórum. Estou utilizando código no listview para quando eu for digitanto no textbox ele já vai filtrando os dados cfe. vou digitando. Tecnicamente esta funcionando, porém o listview esta duplicando o numero de colunas apresentandas, alguém poderia dar uma olhadinha no código para ver onde esta o erro por favor. Desde já obrigado.
Private Sub cdPais_Change()
With ListView1
.Gridlines = True
.View = lvwReport
.FullRowSelect = True
.ColumnHeaders.Add Text:="Cód. Cliente", Width:=50 'País= Nome da 2ª coluna
.ColumnHeaders.Add Text:="Razão Social", Width:=250 'UF= Nome da 3ª coluna
.ColumnHeaders.Add Text:="Cidade", Width:=120 'UF= Nome da 3ª coluna
.ColumnHeaders.Add Text:="Estado", Width:=40 'UF= Nome da 3ª coluna
.ColumnHeaders.Add Text:="Região", Width:=80 'UF= Nome da 3ª coluna
.ColumnHeaders.Add Text:="Outros Dados", Width:=50 'UF= Nome da 3ª coluna
End With
lastRow = Plan6.Cells(Rows.Count, "b").End(xlUp).Row
ListView1.ListItems.Clear
' Adiciona itens
For X = 1 To lastRow
'On Error Resume Next
If UCase(Plan6.Cells(X, 3)) Like "*" & UCase(cdPais) & "*" Then
Set li = ListView1.ListItems.Add(Text:=Plan6.Cells(X, "b").Value)
li.ListSubItems.Add Text:=Plan6.Cells(X, "c").Value
li.ListSubItems.Add Text:=Plan6.Cells(X, "d").Value
li.ListSubItems.Add Text:=Plan6.Cells(X, "e").Value
li.ListSubItems.Add Text:=Plan6.Cells(X, "f").Value
li.ListSubItems.Add Text:=Plan6.Cells(X, "g").Value
End If
Next
End Sub
Private Sub cdPais_Change()
With ListView1
.Gridlines = True
.View = lvwReport
.FullRowSelect = True
.ColumnHeaders.Add Text:="Cód. Cliente", Width:=50 'País= Nome da 2ª coluna
.ColumnHeaders.Add Text:="Razão Social", Width:=250 'UF= Nome da 3ª coluna
.ColumnHeaders.Add Text:="Cidade", Width:=120 'UF= Nome da 3ª coluna
.ColumnHeaders.Add Text:="Estado", Width:=40 'UF= Nome da 3ª coluna
.ColumnHeaders.Add Text:="Região", Width:=80 'UF= Nome da 3ª coluna
.ColumnHeaders.Add Text:="Outros Dados", Width:=50 'UF= Nome da 3ª coluna
End With
lastRow = Plan6.Cells(Rows.Count, "b").End(xlUp).Row
ListView1.ListItems.Clear
' Adiciona itens
For X = 1 To lastRow
'On Error Resume Next
If UCase(Plan6.Cells(X, 3)) Like "*" & UCase(cdPais) & "*" Then
Set li = ListView1.ListItems.Add(Text:=Plan6.Cells(X, "b").Value)
li.ListSubItems.Add Text:=Plan6.Cells(X, "c").Value
li.ListSubItems.Add Text:=Plan6.Cells(X, "d").Value
li.ListSubItems.Add Text:=Plan6.Cells(X, "e").Value
li.ListSubItems.Add Text:=Plan6.Cells(X, "f").Value
li.ListSubItems.Add Text:=Plan6.Cells(X, "g").Value
End If
Next
End Sub