regarding more time to load listview items
i have used listview to select item from it . also i am providing search from text box on key up event in vb6. listview contains approx 36000 item . database is in ms access. it tooks lot of time to display characters and corresponding listview items. pl. help me
i have used following code
vb Code:
Private Sub txtItemName_KeyUp(KeyCode As Integer, Shift As Integer)
On Error GoTo Err_Handler
ListView1.Visible = True
If (KeyCode <> 37 And KeyCode <> 38 And KeyCode <> 39 And KeyCode <> 40 And KeyCode <> 27 And KeyCode <> 13) Then
txtItemName.ForeColor = vbBlack
string1 = Trim(txtItemName.Text) & "%"
ListView1.Visible = True
ListView1.FullRowSelect = True
ListView1.ColumnHeaders.Clear
ListView1.ListItems.Clear
ListView1.View = lvwReport
ListView1.GridLines = True
ListView1.ColumnHeaders.Add , , "Item Name", 3000
ListView1.ColumnHeaders.Add , , "Pkg.", 1200
ListView1.ColumnHeaders.Add , , "Mfg.Code", 1000
Set rs3 = cn.Execute("Select * from M_Itemmaster Where ItemName like '" & string1 & "'")
While Not rs3.EOF
flgFound = True
If Not IsNull(rs3("ItemName")) Then ItemName = rs3("ItemName")
If Not IsNull(rs3("Packing")) Then Packing = rs3("Packing")
If Not IsNull(rs3("MfgCode")) Then MfgCode = rs3("MfgCode")
Set itmX = ListView1.ListItems.Add(, , CStr(ItemName))
itmX.SubItems(1) = CStr(Packing)
itmX.SubItems(2) = CStr(MfgCode)
rs3.MoveNext
Wend
If Not flgFound Then
MsgBox "No Record Exists"
txtItemName.SetFocus
Exit Sub
End If
rs3.Close
Set rs3 = Nothing
ListView1.FullRowSelect = True
ListView1.Visible = True
ElseIf KeyCode = 40 Then
If ListView1.Visible = True Then
ListView1.SetFocus
Set itmX = ListView1.SelectedItem
lblCompany.Caption = ""
Set rs = cn.Execute("Select * From CompanyMaster where MfgCode = '" & itmX.SubItems(2) & "'")
If Not rs.EOF Then
lblCompany.Caption = rs("CompanyName")
End If
rs.Close
Set rs = Nothing
Call AddBatchDetails(itmX)
ListView1.SetFocus
End If
ElseIf KeyCode = 27 Then
Unload Me
' ListView1.Visible = False
End If
Err_Handler:
Exit Sub
Call ERROR_DISPLAY(Err.Number)
End Sub
Re: regarding more time to load listview items
Thread moved from the CodeBank forum (which is for you to post your code examples, not questions)
Manipulating 36000 items in a control (whether a ListView or something else) will always be fairly slow. The chances are that you would get much better speed by re-thinking how this part of the program should be done.
In addition to that, the code you are using may be slowing things down - but we can't tell, as you haven't shown us the code.
Re: regarding more time to load listview items
No one is going to want to wade through 36,000 items to find one thing.
You need to seriously filter what is being displayed at anyone given time.
It looks like you are displaying some kind of items so how about a combo box containing the 26 letters of the alphabet and the listview gets loaded with all items that begin with the selected letter?
Just a suggestion...but, as si__the_geek said, you do need to rethink how this thing works. If you load all 36,000 items in the listview, then it is going to be slow.