ListView Bloqueada só seleciona a primeira coluna

NerdFat

30-07-2015 02:47:50

Boa noite, só consigo selecionar a primeira coluna da minha listview1, tenho outra em outro formulario que consigo selecionar. a listview1 tem alguns filtros e acredito que possa ser isto, o modo com que eu listo (carrego) as informações na listview, mas não tenho certeza, tentei varias maneiras mas sem sucesso, me ajudem por favor, desde já agradeço-lhe(s).

Private Sub ListView1_ItemClick(ByVal Item As MSComctlLib.ListItem)

Label1.Caption = ListView1.SelectedItem
Me.TextBox1.Value = ListView1.SelectedItem.SubItems(2)
end sub
'------------------------------------------------

Private Sub UserForm_Initialize()
Dim hwnd As Long
hwnd = FindWindowA(vbNullString, Me.Caption)
SetWindowLongA hwnd, -16, GetWindowLongA(hwnd, -16) And &HFFF7FFFF
Call PreencheCampos
Me.ComboBoxCampos.ListIndex = 1
Call PreencherListView
Me.Label2.Caption = Format(ListView1.ListItems.Count, "00")
End Sub

Sub PreencherListView()
Dim lastRow As Long
Dim li As ListItem
Dim x As Long

' Adiciona as colunas
With ListView1
.ColumnHeaders.Clear
.Gridlines = True
.View = lvwReport ' Já tirei essa parte e fica desconfigurado

.ColumnHeaders.Add Text:="Cód", Width:=1 '1
.ColumnHeaders.Add Text:="Número", Width:=40 '2
.ColumnHeaders.Add Text:="Resultado", Width:=30 '3

.Gridlines = True 'efeito grade
End With
'...................................................................
'limpar
ListView1.ListItems.Clear

lastRow = PlanFornecedores.Cells(PlanFornecedores.Cells.Rows.Count, "a").End(xlUp).Row

' Adiciona itens
For x = 2 To lastRow
Set li = ListView1.ListItems.Add(Text:=Format(PlanFornecedores.Cells(x, "a").Value, "00")) '1
li.ListSubItems.Add Text:=PlanFornecedores.Cells(x, "b").Value '2
li.ListSubItems.Add Text:=PlanFornecedores.Cells(x, "c").Value
Next
End Sub

Private Sub TextBoxFiltro_Change()
If Me.ComboBoxCampos.ListIndex = -1 Then
MsgBox "Selecione um Campo.", 64, "Treino Listview"
Me.TextBoxFiltro = ""
Exit Sub
End If

Dim strObjetoBuscar As String
Dim lngResultado As Long
'Dim lngColumna As Long, lngFila As Long
Dim a As Integer
Dim coluna
coluna = Me.ComboBoxCampos.ListIndex + 1
ListView1.ListItems.Clear
strObjetoBuscar = TextBoxFiltro.Value
If strObjetoBuscar = "" Then GoTo 99
strObjetoBuscar = LCase(strObjetoBuscar)
For a = 2 To 2010
lngResultado = InStr(1, PlanFornecedores.Cells(a, coluna), strObjetoBuscar, vbTextCompare)
If lngResultado > 0 Then
Set li = ListView1.ListItems.Add(Text:=Format(PlanFornecedores.Range("A" & a).Value, "00")) '1
li.ListSubItems.Add Text:=PlanFornecedores.Range("B" & a).Value
End If
Next a
99:
Me.Label2.Caption = Format(ListView1.ListItems.Count, "00")
End Sub
'######################################################
Private Sub PreencheCampos()
Dim ws As Worksheet
Dim coluna As Integer
Dim linha As Integer
Set ws = ThisWorkbook.Worksheets(NomePlanilha)
coluna = 1 'de 1 para 2
linha = LinhaCabecalho

With ws
While .Cells(linha, coluna).Value <> Empty
Me.ComboBoxCampos.AddItem .Cells(linha, coluna)
coluna = coluna + 1
If coluna = 14 Then Exit Sub 'quantidade de criterios
Wend
End With
End Sub

Private Sub PreencheCabecalho(ByRef Lista())
Dim ws As Worksheet
Dim coluna As Integer
Dim linha As Integer
Set ws = ThisWorkbook.Worksheets(NomePlanilha)
coluna = 1 'de 1 p 2
linha = LinhaCabecalho

With ws
While .Cells(linha, coluna).Value <> Empty
Lista(0, coluna - 1) = .Cells(linha, coluna) 'de -1 p -2
coluna = coluna + 1
Wend
End With
End Sub

Mauro Coutinho

30-07-2015 11:37:39

Se entendi, é só adicionar a instrução :
.FullRowSelect = True abaixo da linha .View = lvwReport

Altere e veja se é isto.

[]s

NerdFat

30-07-2015 17:07:02

Mauro muito obrigado, já havia usado o .FullRowSelect porém sem colocar o = true, o fato de eu não conhecer a sintaxe me fez perder umas 4hs seguida, o dor de cabeça. Muito OBRIGADO.