problem in making listview

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Jul 2007
Posts: 113
Reputation: jaasaria is an unknown quantity at this point 
Solved Threads: 1
jaasaria's Avatar
jaasaria jaasaria is offline Offline
Junior Poster

problem in making listview

 
0
  #1
Feb 28th, 2008
hello, by the way im using datagrid in showing all the data in my database...
here my codes...
'''''''''''''''''''''''''''
form_load

set rs = orecs ("select * from employee")
set datagrid = rs
'''''''''''''''''''''''''''


how can i convert it in list view to view all the data in my database.........

plssssssss kindly help me.........


jaasaria
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 2,099
Reputation: debasisdas will become famous soon enough debasisdas will become famous soon enough 
Solved Threads: 128
debasisdas's Avatar
debasisdas debasisdas is offline Offline
Postaholic

Re: problem in making listview

 
1
  #2
Feb 28th, 2008
Try use this sample code

  1. Private Sub tv1_NodeClick(ByVal Node As MSComctlLib.Node)
  2. LV1.ListItems.Clear
  3. rs.Open "select * from EMP", con, adOpenDynamic, adLockOptimistic
  4.  
  5. Dim li1 As ListItem
  6. Set li1 = LV1.ListItems.Add()
  7. If Not rs.EOF Then
  8.  
  9. If IsNull(rs(0)) Then
  10. li1.Text = ""
  11. Else
  12. li1.Text = rs(0)
  13. End If
  14.  
  15. If IsNull(rs(1)) Then
  16. LV1.ListItems(1).ListSubItems.Add , , ""
  17. Else
  18. LV1.ListItems(1).ListSubItems.Add , , rs(1)
  19. End If
  20.  
  21. If IsNull(rs(2)) Then
  22. LV1.ListItems(1).ListSubItems.Add , , ""
  23. Else
  24. LV1.ListItems(1).ListSubItems.Add , , rs(2)
  25. End If
  26.  
  27. If IsNull(rs(3)) Then
  28. LV1.ListItems(1).ListSubItems.Add , , ""
  29. Else
  30. LV1.ListItems(1).ListSubItems.Add , , rs(3)
  31. End If
  32. If IsNull(rs(4)) Then
  33. LV1.ListItems(1).ListSubItems.Add , , ""
  34. Else
  35. LV1.ListItems(1).ListSubItems.Add , , rs(4)
  36. End If
  37. If IsNull(rs(5)) Then
  38. LV1.ListItems(1).ListSubItems.Add , , ""
  39. Else
  40. LV1.ListItems(1).ListSubItems.Add , , rs(5)
  41. End If
  42. If IsNull(rs(6)) Then
  43. LV1.ListItems(1).ListSubItems.Add , , ""
  44. Else
  45. LV1.ListItems(1).ListSubItems.Add , , rs(6)
  46. End If
  47. If IsNull(rs(7)) Then
  48. LV1.ListItems(1).ListSubItems.Add , , ""
  49. Else
  50. LV1.ListItems(1).ListSubItems.Add , , rs(7)
  51. End If
  52.  
  53. End If
  54. rs.Close
  55. End Sub
Share your Knowledge.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 537
Reputation: choudhuryshouvi is an unknown quantity at this point 
Solved Threads: 49
choudhuryshouvi's Avatar
choudhuryshouvi choudhuryshouvi is offline Offline
Posting Pro

Re: problem in making listview

 
1
  #3
Feb 28th, 2008
check out this sample, try it and give your feedback.

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim str As String
  2. Dim rs As New ADODB.Recordset
  3. Dim li As ListItem
  4.  
  5. str = "select * from org_master order by org_id"
  6. rs.open str, ADODB.adOpenDynamic, ADODB.adUseClient, ADODB.adLockOptimistic
  7.  
  8. lvoffice.ListItems.Clear
  9.  
  10. If rs.RecordCount > 0 Then
  11. rs.MoveFirst
  12. While Not rs.EOF()
  13. With lvoffice
  14. Set li = .ListItems.Add(, , (rs!org_id))
  15. li.SubItems(1) = Replace(rs!org_name, Chr(5), ", ")
  16. li.SubItems(2) = IIf(IsNull(rs!Description), "", Replace(rs!Description, Chr(5), ", "))
  17. End With
  18. rs.MoveNext
  19. Wend
  20. End If
  21.  
  22. If rs.state = adStateOpen Then rs.Close
  23. Set rs = Nothing

regards
Shouvik
Shouvik_The_Expert_Coder
Have a problem? Don't worry just give me a call and I'll fix it for you.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 113
Reputation: jaasaria is an unknown quantity at this point 
Solved Threads: 1
jaasaria's Avatar
jaasaria jaasaria is offline Offline
Junior Poster

Re: problem in making listview

 
0
  #4
Feb 29th, 2008
elow ..choudhuryshouvi..
the code that you given was an error to my system...(invalid property value)
i dont know wat the problem but i dont know the purpose of chr(5)..
can you make another to right for me..

elow..debasisdas...
by the way the code that you given it not working....
their no error but only listview without any data...
my datagrid contain some..but my listview dont have any one...


plzzzzzzzzzz help me guyzzzzzzzzzzzz...

thx for the post
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 537
Reputation: choudhuryshouvi is an unknown quantity at this point 
Solved Threads: 49
choudhuryshouvi's Avatar
choudhuryshouvi choudhuryshouvi is offline Offline
Posting Pro

Re: problem in making listview

 
0
  #5
Mar 1st, 2008
there is no relation of chr(5) with the error "invalid property value".

this "chr(5)"was used by me in one of my application to retrieve value from one of the tables after just replacing the ascii code of vbnewline to ",".you can skip this character. there is no need of it in your code.

do you know what is the meaning of this error msg?
if don't then listen,
vb6 compiler returns this error if any column to which you are adding data doesn't exist in the listview at all.

you must have similar number of columns in the listview the no. of times you fire this li.subitems statement before adding data.
in this command li.subitems(1), the numeral within the paranthesis refers to the column to which you are adding data. you can consider it like an array. but in this case the lbound starts from 1. if the compiler doesn't find the column at the specified index position in the listview it fetches you "invalid property value" error.
to add data into the first col of the lv you use
set li=.listitems.add(,,(<your data to be added>))
then from second to n-th no. of columns you use li.subitems(<col. index no.>)=<your data to be added>

so as much as i told u the error was in your target lv not in the code and it would never be because it was used in several forms of my application and tested many times.

so before run this code make sure you have sufficient no. of columns in your listview control.
e.g., in the sample code that i gave you, the listview should contain atleast 3 columns to successfully complete execution of the code.

i hope this lecture will help you to solve your problem.

ok.....
don't forget to tell me what hv u got

regards
Shouvik
Last edited by choudhuryshouvi; Mar 1st, 2008 at 3:58 am.
Shouvik_The_Expert_Coder
Have a problem? Don't worry just give me a call and I'll fix it for you.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 113
Reputation: jaasaria is an unknown quantity at this point 
Solved Threads: 1
jaasaria's Avatar
jaasaria jaasaria is offline Offline
Junior Poster

Re: problem in making listview

 
0
  #6
Mar 3rd, 2008
hi choudhuryshouvi...

already try it but i cant'. im so sorry.. i will give you my database for testing...
kindly sent to me the complete example of your by using my table??
i will get an idea on how...
just kindly make any 1 of the table. thxx in advance..

jaasaria
Attached Files
File Type: zip asa.zip (59.1 KB, 4 views)
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 537
Reputation: choudhuryshouvi is an unknown quantity at this point 
Solved Threads: 49
choudhuryshouvi's Avatar
choudhuryshouvi choudhuryshouvi is offline Offline
Posting Pro

Re: problem in making listview

 
0
  #7
Mar 3rd, 2008
ok i took the customer table and this is the code for it.
focus on the bolded part.

Dim db As Database
Dim rs As Recordset
Dim li As ListItem

Set db = OpenDatabase(App.Path & "\asa.mdb")
Set rs = db.OpenRecordset("customer", dbOpenTable)

If rs.RecordCount > 0 Then
    rs.MoveFirst
    While Not rs.EOF()
        With lvcustomers
            Set li = .ListItems.Add(, , (rs!cus_num))
            li.SubItems(1) = IIf(IsNull(rs!cus_name), "", rs!cus_name)
            li.SubItems(2) = IIf(IsNull(rs!cus_tel), "", rs!cus_tel)
            li.SubItems(3) = IIf(IsNull(rs!cus_add), "", rs!cus_add)
        End With
        rs.MoveNext
    Wend
End If

also see the snapshot.

regards
Shouvik
Attached Thumbnails
snapshot.JPG  
Shouvik_The_Expert_Coder
Have a problem? Don't worry just give me a call and I'll fix it for you.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 2,099
Reputation: debasisdas will become famous soon enough debasisdas will become famous soon enough 
Solved Threads: 128
debasisdas's Avatar
debasisdas debasisdas is offline Offline
Postaholic

Re: problem in making listview

 
0
  #8
Mar 3rd, 2008
Originally Posted by jaasaria View Post
elow..debasisdas...
by the way the code that you given it not working....
their no error but only listview without any data...
my datagrid contain some..but my listview dont have any one...
That code works fine for me.
Try to run the code in debug mode and check .

Actually that code was to populate the list view from a tree view selection.

Try using on button click event
Last edited by debasisdas; Mar 3rd, 2008 at 6:02 am.
Share your Knowledge.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 113
Reputation: jaasaria is an unknown quantity at this point 
Solved Threads: 1
jaasaria's Avatar
jaasaria jaasaria is offline Offline
Junior Poster

Re: problem in making listview

 
0
  #9
Mar 3rd, 2008
elow shouvi and debasisdas...ohwss... by the way i get it.. i know where i get wrong...
the list view is not set by their column header.. that why what ever code i put something gets wrong..like shouvi said... im so very grateful.. thx for the help..

thxx so muchhh......1000x

jaasaria
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: problem in making listview

 
0
  #10
Jan 23rd, 2009
hi,
i have found this post somewhat close to solving my problem, but there seem to be a problem. Kindly help me with the code....i am posting the code
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Set db = OpenDatabase(App.Path & "\libraryic.mdb")
  2. Set rs = db.OpenRecordset("Book_Details", dbOpenTable)
  3.  
  4. ''Do While Not Form1.Data1.Recordset.EOF
  5. ''Data1.Recordset.MoveNext
  6. ''While Not Data1.Recordset.EOF
  7. If rs.RecordCount > 0 Then
  8. rs.MoveFirst
  9. While Not rs.EOF()
  10. With BooK_Details
  11. li = .ListItems.Add(, , (rs!Acc_No))
  12. li.SubItems(1) = IIf(IsNull(rs!Book_Name), "", rs!Book_Name)
  13. li.SubItems(2) = IIf(IsNull(rs!Author), "", rs!Author)
  14. li.SubItems(3) = IIf(IsNull(rs!Publisher), "", rs!Publisher)
  15. li.SubItems(4) = IIf(IsNull(rs!Stock), "", rs!Stock)
  16. End With
  17. rs.MoveNext
  18. Wend

But nothing gets displayed on the Listview..... actually i am searching a particular book name

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Form7.Data1.RecordSource = "select * from Book_Details where Book_Name like '" & SearchStr$ & "%'" ' or Book_Name like '" & SearchStr$ & "'"
  2. Form7.Data1.Refresh

i will be grateful for anykind of help..
thanks.
You cant get to where you are going unless you know where you have been.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
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