Hi, hope everyone here is dong fine.
Can anyone please help me with my coding.
This is the code to fetch the book name from INPUT box and display it in a TextBox(which is limited). But I want the records to be displayed on a ListView with several others having similar(closest to) name. But I am struggling with the code on how to show the records in ListView.

prompt$ = "Please enter the book name"
SearchStr$ = InputBox(prompt$, "book title search")
Data1.Recordset.FindFirst "Book_Name='" & SearchStr$ & "'"
If Data1.Recordset.NoMatch Then
MsgBox "No match found", vbInformation, ""
Form7.Data1.RecordSource = "select * from Books where Book_Name = '" & SearchStr$ & "'" 	‘hope I can use LIKE with  
                                                        % to display more similar names
Form7.Text1.Text = Form7.Data1.Recordset.Fields(0)
Form7.Text2.Text = Form7.Data1.Recordset.Fields(1)
Form7.Text3.Text = Form7.Data1.Recordset.Fields(2)
End If

I tried to create the columns using this codes:

ListView1.Columns.Add("Title", 10, HorizontalAlignment.Left)

Which is not working!!
And how do i add the records from the database??

Basically I am struggling with the code to display the records on ListView from the Database. Can anyone please give me some hints.

Thanks a lot.

9 Years
Discussion Span
Last Post by hkdani

Basically I am struggling with the code to display the records on ListView from the Database. Can anyone please give me some hints.

Basically you just use the Add method of list view Listview.listItems.Add Index, Key, Text, Icon, SmallIcon as ListItem If you're using a database recordset, you might try using a loop with the EOF property.

With MyDatabase
     while Not .EOF
         ListView1.ListItems.Add , , .Fields("MyFoundField")
End with

I don't use these listviews much; but I think that the Columns property is intended to design the listview on the fiy. If you want to add items, I would say to use the ListItems Method.


Thanks hkdani for the help. I have tried it in the application and its working(partly). I can display the data’s in ListView. But it just displays the data’s in a random manner and also without column names. (no rows or columns….just one line or in multiple lines)
I first query for a name in my Find/Search text box like,

select * from Book_Details where Book_Name = '" & SearchStr$ & "' or Book_Name like '%SearchStr%'"

I hope this is a standard code… and then result of this query is to be displayed in a ListView1. So I used your code..

With Data1.Recordset
    While Not .EOF
         Form11.ListView1.ListItems.Add , , .Fields("Book_Name")
         Form11.ListView1.ListItems.Add , , .Fields("Author")
End With

Now this code displays the data’s but without the column names and that too in a random manner. Can anyone please suggest how to correct this.
Thanks again.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.