I need to add the function to be marked EnsureVisible row in the listview
Module load ListView
Code:
Public Sub CargarListView_Cliente(LV_Cliente As ListView, rs As ADODB.Recordset)
On Error GoTo ErrorSub
LV_Cliente.ListItems.Clear
If rs.RecordCount > 0 Then
While Not rs.EOF
Set objItem = LV_Cliente.ListItems.Add(, , rs(0))
objItem.SubItems(1) = rs!name
objItem.SubItems(2) = rs!age
objItem.SubItems(3) = rs!address
rs.MoveNext
Wend
End If
Exit Sub
ErrorSub:
If Err.Number = 94 Then Resume Next
End Sub
Form1
Code:
Private Sub Form_Load()
CargarListView_Cliente LV_Cliente, rs
End Sub
Private Sub LV_Cliente_DblClick()
Dim i As Integer
With form2
.IdCliente = LV_Cliente.SelectedItem.Text
For i = 1 To 3
.Text1(i).Text = LV_Cliente.SelectedItem.ListSubItems(i).Text
Next
.Show vbModal
End With
End Sub
Form2
Code:
Public IdCliente
Private Sub cmdSave_Click()
On Error GoTo ErrorSub
cnn.Execute "UPDATE cliente set name = '" & Trim(Text1(1)) & _
"', age = '" & Trim(Text1(2)) & _
"', address = '" & Trim(Text1(3)) & _
"' where id_cliente = " & IdCliente & ""
rs.Requery 1
Call CargarListView_Cliente(Form1.LV_Cliente, rs)
DoEvents
Unload Me
Set Form2 = Nothing
Exit Sub
ErrorSub:
MsgBox Err.Description
End Sub
I'm not quite sure I follow, but there's a standard macro for EnsureVisible:
Code:
Public Const LVM_FIRST = &H1000
Public Const LVM_ENSUREVISIBLE = (LVM_FIRST + 19)
Public Function ListView_EnsureVisible(hwndLV As Long, i As Long, fPartialOK As Long) As Boolean
ListView_EnsureVisible = SendMessage(hwndLV, LVM_ENSUREVISIBLE, ByVal i, ByVal fPartialOK)
End Function