listview movelast

dukeman1
12-18-2003, 08:44 AM
I'm working on the listview with columes. My problem is when form is loaded , my long listview will by automatically show from the first item only . It takes time for me to scroll down every time i want to see my inserted new data. Maybe my code is wrong. Please help

Private Sub Display_Listview()
Dim rs As New ADODB.Recordset
Dim rec As Integer
Dim str
Dim mItem As ListItem
lvItem.ListItems.Clear
str = "select * from chip order by stt asc, so asc, trang asc"
rs.Open str, cn, adOpenKeyset, adLockOptimistic, adCmdText
If rs.EOF = False Then
While Not rs.EOF
Set mItem = lvItem.ListItems.Add(, , rs!stt)
mItem.SubItems(1) = rs!so
mItem.SubItems(2) = rs!trang
mItem.SubItems(3) = rs!tacgia
mItem.SubItems(4) = rs!tuade
rs.MoveNext
Wend
End If
End Sub

00100b
12-18-2003, 08:56 AM
Add one line of code right before the rs.MoveNext statement.

mItem.EnsureVisible = True

To have the last, newly added ListItem selected, set its Selected property to True.

dukeman1
12-18-2003, 10:21 AM
Hi again
i did what u said, but there was an error "Function call on left hand side of assignment must return Variant or Object". What should i do next?
by the way , how to set select property for new added item, i cannot find where to put it

00100b
12-18-2003, 10:34 AM
For the first part, could you repost your code.

For the second part,

mItem.Selected = True

dukeman1
12-18-2003, 10:50 AM
Private Sub Display_Listview()
Dim rs As New ADODB.Recordset
Dim str
Dim mItem As ListItem
lvItem.ListItems.Clear
str = "select * from chip order by stt asc, so asc, trang asc"
rs.Open str, cn, adOpenKeyset, adLockOptimistic, adCmdText
If rs.EOF = False Then
While Not rs.EOF
Set mItem = lvItem.ListItems.Add(, , rs!stt)
mItem.SubItems(1) = rs!so
mItem.SubItems(2) = rs!trang
mItem.SubItems(3) = rs!tacgia
mItem.SubItems(4) = rs!tuade
mItem.EnsureVisible = True
rs.MoveNext
Wend
End If
mitem.Selected = True


This "mItem.Selected = True" works like when i move my mouse on one of the item, its automatically highlighted
Please help

00100b
12-18-2003, 11:21 AM
Ack! My bad.

It's just

mItem.EnsureVisible

It's a method call not a property setting.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum