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.MoveFirst
Data1.Recordset.FindFirst "Book_Name='" & SearchStr$ & "'"
If Data1.Recordset.NoMatch Then
MsgBox "No match found", vbInformation, ""
Else
Form7.Show
Form7.Data1.RecordSource = "select * from Books where Book_Name = '" & SearchStr$ & "'" 	‘hope I can use LIKE with  
                                                        % to display more similar names
Form7.Data1.Refresh
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.

Recommended Answers

All 3 Replies

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
     .MoveFirst
     while Not .EOF
         ListView1.ListItems.Add , , .Fields("MyFoundField")
         .MoveNext
      Wend
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
    .MoveNext
    While Not .EOF
         Form11.ListView1.ListItems.Add , , .Fields("Book_Name")
         Form11.ListView1.ListItems.Add , , .Fields("Author")
         	……………….
…………….
         .MoveNext
         Wend
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.

http://msdn.microsoft.com/en-us/library/aa733652(VS.60).aspx
The above was just my meager attempt to get you started. You need to use the report format. The MSDN link above should give you the information you need to accomplish your task.

Hank

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.