Help with Search & ListView codes.

Reply

Join Date: Jun 2008
Posts: 33
Reputation: chanthung is an unknown quantity at this point 
Solved Threads: 0
chanthung's Avatar
chanthung chanthung is offline Offline
Light Poster

Help with Search & ListView codes.

 
0
  #1
Nov 24th, 2008
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.

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. prompt$ = "Please enter the book name"
  2. SearchStr$ = InputBox(prompt$, "book title search")
  3. Data1.Recordset.MoveFirst
  4. Data1.Recordset.FindFirst "Book_Name='" & SearchStr$ & "'"
  5. If Data1.Recordset.NoMatch Then
  6. MsgBox "No match found", vbInformation, ""
  7. Else
  8. Form7.Show
  9. Form7.Data1.RecordSource = "select * from Books where Book_Name = '" & SearchStr$ & "'" ‘hope I can use LIKE with
  10. % to display more similar names
  11. Form7.Data1.Refresh
  12. Form7.Text1.Text = Form7.Data1.Recordset.Fields(0)
  13. Form7.Text2.Text = Form7.Data1.Recordset.Fields(1)
  14. Form7.Text3.Text = Form7.Data1.Recordset.Fields(2)
  15. End If

I tried to create the columns using this codes:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. 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.
You cant get to where you are going unless you know where you have been.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 218
Reputation: hkdani is an unknown quantity at this point 
Solved Threads: 24
hkdani's Avatar
hkdani hkdani is offline Offline
Posting Whiz in Training

Re: Help with Search & ListView codes.

 
0
  #2
Nov 24th, 2008
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.
Last edited by hkdani; Nov 24th, 2008 at 5:05 pm.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 33
Reputation: chanthung is an unknown quantity at this point 
Solved Threads: 0
chanthung's Avatar
chanthung chanthung is offline Offline
Light Poster

Re: Help with Search & ListView codes.

 
0
  #3
Nov 28th, 2008
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,
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. 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..
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. With Data1.Recordset
  2. .MoveNext
  3. While Not .EOF
  4. Form11.ListView1.ListItems.Add , , .Fields("Book_Name")
  5. Form11.ListView1.ListItems.Add , , .Fields("Author")
  6. ……………….
  7. …………….
  8. .MoveNext
  9. Wend
  10. 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.
You cant get to where you are going unless you know where you have been.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 218
Reputation: hkdani is an unknown quantity at this point 
Solved Threads: 24
hkdani's Avatar
hkdani hkdani is offline Offline
Posting Whiz in Training

Re: Help with Search & ListView codes.

 
0
  #4
Nov 28th, 2008
http://msdn.microsoft.com/en-us/libr...52(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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC