SELECIONAR LINHA DO LISTVIEW E PASSAR DADOS.......

CAMILAPOSSER 25/10/2012 14:55:18
#412802
tenho uma tela de pesquisa (codigo abaixo) e nela gostaria de selecionar uma linha do listview e ao dar dois cliques passar os dados para a tela do cadastro.

Private Const NomePlanilha As String = [Ô]grupos[Ô]
Private Const LinhaCabecalho As Integer = 1

Private Sub btnfechar_Click()
Me.Hide
frm_menu.Show

End Sub

Private Sub ComboBoxCampos_Change()
Me.TextBoxFiltro.SetFocus
End Sub


Private Sub UserForm_Initialize()

Call PreencheCampos
Me.ComboBoxCampos.ListIndex = 1
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
[ô].FullRowSelect
.ColumnHeaders.Add Text:=[Ô]Código[Ô], Width:=30
.ColumnHeaders.Add Text:=[Ô]Universidade[Ô], Width:=80
.ColumnHeaders.Add Text:=[Ô]Linha[Ô], Width:=160
.ColumnHeaders.Add Text:=[Ô]NomedoGrupo[Ô], Width:=120
.ColumnHeaders.Add Text:=[Ô]LinhasdePesquisa[Ô], Width:=200
.ColumnHeaders.Add Text:=[Ô]LiderdoGrupo[Ô], Width:=70
.ColumnHeaders.Add Text:=[Ô]ViceLider[Ô], Width:=70
.ColumnHeaders.Add Text:=[Ô]Região[Ô], Width:=45

[ô] .Gridlines = True [ô]efeito grade
End With
[ô]...................................................................
[ô]limpar
ListView1.ListItems.Clear

lastRow = Plan1.Cells(Plan1.Cells.Rows.Count, [Ô]a[Ô]).End(xlUp).Row

[ô] Adiciona itens
For X = 2 To lastRow
Set li = ListView1.ListItems.Add(Text:=Format(Plan1.Cells(X, [Ô]a[Ô]).Value, [Ô]00[Ô]))
li.ListSubItems.Add Text:=Plan1.Cells(X, [Ô]b[Ô]).Value
li.ListSubItems.Add Text:=Plan1.Cells(X, [Ô]c[Ô]).Value
li.ListSubItems.Add Text:=Plan1.Cells(X, [Ô]d[Ô]).Value
li.ListSubItems.Add Text:=Plan1.Cells(X, [Ô]e[Ô]).Value
li.ListSubItems.Add Text:=Plan1.Cells(X, [Ô]f[Ô]).Value
li.ListSubItems.Add Text:=Plan1.Cells(X, [Ô]g[Ô]).Value
li.ListSubItems.Add Text:=Plan1.Cells(X, [Ô]h[Ô]).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, Plan1.Cells(a, coluna), strObjetoBuscar, vbTextCompare)
If lngResultado > 0 Then
Set li = ListView1.ListItems.Add(Text:=Format(Plan1.Range([Ô]A[Ô] & a).Value, [Ô]00[Ô]))
li.ListSubItems.Add Text:=Plan1.Range([Ô]B[Ô] & a).Value
li.ListSubItems.Add Text:=Plan1.Range([Ô]C[Ô] & a).Value
li.ListSubItems.Add Text:=Plan1.Range([Ô]D[Ô] & a).Value
li.ListSubItems.Add Text:=Plan1.Range([Ô]E[Ô] & a).Value
li.ListSubItems.Add Text:=Plan1.Range([Ô]F[Ô] & a).Value
li.ListSubItems.Add Text:=Plan1.Range([Ô]G[Ô] & a).Value
li.ListSubItems.Add Text:=Plan1.Range([Ô]H[Ô] & 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 = 13 Then Exit Sub
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




NICOLLAS2 25/10/2012 16:52:32
#412815

Private Sub ListView1_DblClick()

text1.text = Listview1.SelectedItem.ListSubItems(1)
text2.text = Listview1.SelectedItem.ListSubItems(2)
text3.text = Listview1.SelectedItem.ListSubItems(3)

End Sub
Tópico encerrado , respostas não são mais permitidas