Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Faster way to populate listview...

Could someone please give me some code for a faster way of achieving the following? ("Results" is an SQL Query)

Do
Form1.ListView1.ListItems.Add , , Results(0)
Results.MoveNext
Loop Until Results.EOF
Results.MoveFirst
X = 1
Do
Form1.ListView1.ListItems(X).SubItems(1) = Results(1)
X = X + 1
Results.MoveNext
Loop Until Results.EOF
Results.MoveFirst
X = 1
Do
Form1.ListView1.ListItems(X).SubItems(2) = Format(Results(2), "currency")
X = X + 1
Results.MoveNext
Loop Until Results.EOF
Results.MoveFirst
X = 1
Do
Form1.ListView1.ListItems(X).SubItems(3) = Results(3)
X = X + 1
Results.MoveNext
Loop Until Results.EOF
Results.MoveFirst
X = 1
Do
Form1.ListView1.ListItems(X).SubItems(4) = Results(4)
X = X + 1
Results.MoveNext
Loop Until Results.EOF
Set Results = Nothing

Adding the items from the recordset to the listview takes almost a minute doing it this way. Any help would be appreciated! Thanks in advance.




Comments

  • GogiGogi Posts: 258Member
    I am using something like this one:
    [code]
    'I use ADO control

    Dim n As Integer
    Dim x As Integer
    For n=1 To ado.Recordset.RecordCount

    ListView1.ListItems.Add ,,ado.Recordset.Fields.Item(0).Value

    x=ListView1.ListItems.Count

    ListView1.ListItems.Item(x).Subitems(1)=ado.Recordset.Fields.Item(1)
    ListView1.ListItems.Item(x).Subitems(2)=ado.Recordset.Fields.Item(2)
    '...

    Next n

    [/code]

    Hope this helps!

    Gogi

  • david77057david77057 Posts: 6Member
    : I am using something like this one:
    : [code]
    : 'I use ADO control
    :
    : Dim n As Integer
    : Dim x As Integer
    : For n=1 To ado.Recordset.RecordCount
    :
    : ListView1.ListItems.Add ,,ado.Recordset.Fields.Item(0).Value
    :
    : x=ListView1.ListItems.Count
    :
    : ListView1.ListItems.Item(x).Subitems(1)=ado.Recordset.Fields.Item(1)
    : ListView1.ListItems.Item(x).Subitems(2)=ado.Recordset.Fields.Item(2)
    : '...
    :
    : Next n
    :
    : [/code]
    :
    : Hope this helps!
    :
    : Gogi
    :
    :
    Hi,

    I'm getting "Object required" on
    For n = 1 To ado.Recordset.RecordCount

    Now, am I changing "Recordset" to the name of my recordset ("Results")? That am I missing?


  • GogiGogi Posts: 258Member
    : : I am using something like this one:
    : : [code]
    : : 'I use ADO control
    : :
    : : Dim n As Integer
    : : Dim x As Integer
    : : For n=1 To ado.Recordset.RecordCount
    : :
    : : ListView1.ListItems.Add ,,ado.Recordset.Fields.Item(0).Value
    : :
    : : x=ListView1.ListItems.Count
    : :
    : : ListView1.ListItems.Item(x).Subitems(1)=ado.Recordset.Fields.Item(1)
    : : ListView1.ListItems.Item(x).Subitems(2)=ado.Recordset.Fields.Item(2)
    : : '...
    : :
    : : Next n
    : :
    : : [/code]
    : :
    : : Hope this helps!
    : :
    : : Gogi
    : :
    : :
    : Hi,
    :
    : I'm getting "Object required" on
    : For n = 1 To ado.Recordset.RecordCount
    :
    : Now, am I changing "Recordset" to the name of my recordset ("Results")? That am I missing?
    :
    :
    :

    Well,try to use Results instead of ado.Recordset!
    My code was just an example...you have to change the names in the code...

    Best regards,
    Gogi.

  • david77057david77057 Posts: 6Member
    : : : I am using something like this one:
    : : : [code]
    : : : 'I use ADO control
    : : :
    : : : Dim n As Integer
    : : : Dim x As Integer
    : : : For n=1 To ado.Recordset.RecordCount
    : : :
    : : : ListView1.ListItems.Add ,,ado.Recordset.Fields.Item(0).Value
    : : :
    : : : x=ListView1.ListItems.Count
    : : :
    : : : ListView1.ListItems.Item(x).Subitems(1)=ado.Recordset.Fields.Item(1)
    : : : ListView1.ListItems.Item(x).Subitems(2)=ado.Recordset.Fields.Item(2)
    : : : '...
    : : :
    : : : Next n
    : : :
    : : : [/code]
    : : :
    : : : Hope this helps!
    : : :
    : : : Gogi
    : : :
    : : :
    : : Hi,
    : :
    : : I'm getting "Object required" on
    : : For n = 1 To ado.Recordset.RecordCount
    : :
    : : Now, am I changing "Recordset" to the name of my recordset ("Results")? That am I missing?
    : :
    : :
    : :
    :
    : Well,try to use Results instead of ado.Recordset!
    : My code was just an example...you have to change the names in the code...
    :
    : Best regards,
    : Gogi.
    :
    :
    Hi. I tried that...still get the same error. Is it in my connection? Here is some of my code:

    Function OpenDBFConn(path)

    Dim Conn: Set Conn = CreateObject("ADODB.Connection")
    Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=c:/data;" & _
    "Extended Properties=""dBase III;"";"
    Set OpenDBFConn = Conn

    End Function

    Private Sub Command1_Click()
    Set DBConn = OpenDBFConn("c:data")
    Dim Results

    Set Results = DBConn.Execute("Select ITM_DSCRPT, STD_PRICE from[items#DBF] where ITM_DSCRPT like '%" & Text1.Text & "%' order by ITM_DSCRPT")

    'I added your code here...

    End Sub
  • GogiGogi Posts: 258Member
    : : : : I am using something like this one:
    : : : : [code]
    : : : : 'I use ADO control
    : : : :
    : : : : Dim n As Integer
    : : : : Dim x As Integer
    : : : : For n=1 To ado.Recordset.RecordCount
    : : : :
    : : : : ListView1.ListItems.Add ,,ado.Recordset.Fields.Item(0).Value
    : : : :
    : : : : x=ListView1.ListItems.Count
    : : : :
    : : : : ListView1.ListItems.Item(x).Subitems(1)=ado.Recordset.Fields.Item(1)
    : : : : ListView1.ListItems.Item(x).Subitems(2)=ado.Recordset.Fields.Item(2)
    : : : : '...
    : : : :
    : : : : Next n
    : : : :
    : : : : [/code]
    : : : :
    : : : : Hope this helps!
    : : : :
    : : : : Gogi
    : : : :
    : : : :
    : : : Hi,
    : : :
    : : : I'm getting "Object required" on
    : : : For n = 1 To ado.Recordset.RecordCount
    : : :
    : : : Now, am I changing "Recordset" to the name of my recordset ("Results")? That am I missing?
    : : :
    : : :
    : : :
    : :
    : : Well,try to use Results instead of ado.Recordset!
    : : My code was just an example...you have to change the names in the code...
    : :
    : : Best regards,
    : : Gogi.
    : :
    : :
    : Hi. I tried that...still get the same error. Is it in my connection? Here is some of my code:
    :
    : Function OpenDBFConn(path)
    :
    : Dim Conn: Set Conn = CreateObject("ADODB.Connection")
    : Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    : "Data Source=c:/data;" & _
    : "Extended Properties=""dBase III;"";"
    : Set OpenDBFConn = Conn
    :
    : End Function
    :
    : Private Sub Command1_Click()
    : Set DBConn = OpenDBFConn("c:data")
    : Dim Results
    :
    : Set Results = DBConn.Execute("Select ITM_DSCRPT, STD_PRICE from[items#DBF] where ITM_DSCRPT like '%" & Text1.Text & "%' order by ITM_DSCRPT")
    :
    : 'I added your code here...
    :
    : End Sub
    :

    Hi!

    Really,I've never worked with the connection object,so I don't know what's wrong.I always use ADO control,and it's very good for me.

    If someone else has a solution,please post it here.

    Best regards,
    Gogi

  • david77057david77057 Posts: 6Member
    : : : : : I am using something like this one:
    : : : : : [code]
    : : : : : 'I use ADO control
    : : : : :
    : : : : : Dim n As Integer
    : : : : : Dim x As Integer
    : : : : : For n=1 To ado.Recordset.RecordCount
    : : : : :
    : : : : : ListView1.ListItems.Add ,,ado.Recordset.Fields.Item(0).Value
    : : : : :
    : : : : : x=ListView1.ListItems.Count
    : : : : :
    : : : : : ListView1.ListItems.Item(x).Subitems(1)=ado.Recordset.Fields.Item(1)
    : : : : : ListView1.ListItems.Item(x).Subitems(2)=ado.Recordset.Fields.Item(2)
    : : : : : '...
    : : : : :
    : : : : : Next n
    : : : : :
    : : : : : [/code]
    : : : : :
    : : : : : Hope this helps!
    : : : : :
    : : : : : Gogi
    : : : : :
    : : : : :
    : : : : Hi,
    : : : :
    : : : : I'm getting "Object required" on
    : : : : For n = 1 To ado.Recordset.RecordCount
    : : : :
    : : : : Now, am I changing "Recordset" to the name of my recordset ("Results")? That am I missing?
    : : : :
    : : : :
    : : : :
    : : :
    : : : Well,try to use Results instead of ado.Recordset!
    : : : My code was just an example...you have to change the names in the code...
    : : :
    : : : Best regards,
    : : : Gogi.
    : : :
    : : :
    : : Hi. I tried that...still get the same error. Is it in my connection? Here is some of my code:
    : :
    : : Function OpenDBFConn(path)
    : :
    : : Dim Conn: Set Conn = CreateObject("ADODB.Connection")
    : : Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    : : "Data Source=c:/data;" & _
    : : "Extended Properties=""dBase III;"";"
    : : Set OpenDBFConn = Conn
    : :
    : : End Function
    : :
    : : Private Sub Command1_Click()
    : : Set DBConn = OpenDBFConn("c:data")
    : : Dim Results
    : :
    : : Set Results = DBConn.Execute("Select ITM_DSCRPT, STD_PRICE from[items#DBF] where ITM_DSCRPT like '%" & Text1.Text & "%' order by ITM_DSCRPT")
    : :
    : : 'I added your code here...
    : :
    : : End Sub
    : :
    :
    : Hi!
    :
    : Really,I've never worked with the connection object,so I don't know what's wrong.I always use ADO control,and it's very good for me.
    :
    : If someone else has a solution,please post it here.
    :
    : Best regards,
    : Gogi
    :
    :
    Gogi,

    Thanks anyway for trying to help. Much appreciated.




Sign In or Register to comment.