Try use this sample code
Private Sub tv1_NodeClick(ByVal Node As MSComctlLib.Node)
LV1.ListItems.Clear
rs.Open "select * from EMP", con, adOpenDynamic, adLockOptimistic
Dim li1 As ListItem
Set li1 = LV1.ListItems.Add()
If Not rs.EOF Then
If IsNull(rs(0)) Then
li1.Text = ""
Else
li1.Text = rs(0)
End If
If IsNull(rs(1)) Then
LV1.ListItems(1).ListSubItems.Add , , ""
Else
LV1.ListItems(1).ListSubItems.Add , , rs(1)
End If
If IsNull(rs(2)) Then
LV1.ListItems(1).ListSubItems.Add , , ""
Else
LV1.ListItems(1).ListSubItems.Add , , rs(2)
End If
If IsNull(rs(3)) Then
LV1.ListItems(1).ListSubItems.Add , , ""
Else
LV1.ListItems(1).ListSubItems.Add , , rs(3)
End If
If IsNull(rs(4)) Then
LV1.ListItems(1).ListSubItems.Add , , ""
Else
LV1.ListItems(1).ListSubItems.Add , , rs(4)
End If
If IsNull(rs(5)) Then
LV1.ListItems(1).ListSubItems.Add , , ""
Else
LV1.ListItems(1).ListSubItems.Add , , rs(5)
End If
If IsNull(rs(6)) Then
LV1.ListItems(1).ListSubItems.Add , , ""
Else
LV1.ListItems(1).ListSubItems.Add , , rs(6)
End If
If IsNull(rs(7)) Then
LV1.ListItems(1).ListSubItems.Add , , ""
Else
LV1.ListItems(1).ListSubItems.Add , , rs(7)
End If
End If
rs.Close
End Sub
debasisdas
Posting Genius
6,872 posts since Feb 2007
Reputation Points: 666
Solved Threads: 434
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
debasisdas
Posting Genius
6,872 posts since Feb 2007
Reputation Points: 666
Solved Threads: 434
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
Set db = OpenDatabase(App.Path & "\libraryic.mdb")
Set rs = db.OpenRecordset("Book_Details", dbOpenTable)
''Do While Not Form1.Data1.Recordset.EOF
''Data1.Recordset.MoveNext
''While Not Data1.Recordset.EOF
If rs.RecordCount > 0 Then
rs.MoveFirst
While Not rs.EOF()
With BooK_Details
li = .ListItems.Add(, , (rs!Acc_No))
li.SubItems(1) = IIf(IsNull(rs!Book_Name), "", rs!Book_Name)
li.SubItems(2) = IIf(IsNull(rs!Author), "", rs!Author)
li.SubItems(3) = IIf(IsNull(rs!Publisher), "", rs!Publisher)
li.SubItems(4) = IIf(IsNull(rs!Stock), "", rs!Stock)
End With
rs.MoveNext
Wend
But nothing gets displayed on the Listview..... actually i am searching a particular book name
Form7.Data1.RecordSource = "select * from Book_Details where Book_Name like '" & SearchStr$ & "%'" ' or Book_Name like '" & SearchStr$ & "'"
Form7.Data1.Refresh
i will be grateful for anykind of help..
thanks.
chanthung
Junior Poster in Training
52 posts since Jun 2008
Reputation Points: 10
Solved Threads: 0
first of all my apology to all for reopening this SOLVED thread.
I am knid of new to vb programming, so maybe i am missing something. But Thanks a lot for the help. Actually i am still getting error. My actual connection is DSN. so do i have to write the code differently to connect my databse to ListView1..? I am kind of struggling with ListView and Database connection using DSN.
Set Li = . ListItems.Add (, ,(rs!Acc_No)) is corrected as you have instructed.
I am still getting this message when i compile.
Runtime Eror : '424'
Object Required
Thanks a lot again.
Have a good day.
chanthung
Junior Poster in Training
52 posts since Jun 2008
Reputation Points: 10
Solved Threads: 0
Thanks to both of you for sharing your knowledge and sorry for my late response. Ok, so here is my code. This part of my program will accept a Book Name from the user and search through the database and display it in the List View else display Book not found message. Problem is I can’t find about List View in Books I am referring to. So I will be so grateful for help or suggestions..
Private Sub Command13_Click()
Dim db As Database ‘Copied from your previous post.
Dim rs As Recordset
Dim li As ListItem
prompt$ = "Please enter full book name"
SearchStr$ = InputBox(prompt$, "book title search")
If SearchStr$ = "" Then Exit Sub ‘ Accept the Book Name
' from the user
Form7.Data1.RecordSource = "select * from Book_Details where Book_Name like '" & SearchStr$ & "%'"
Form7.Data1.Refresh
Set db = OpenDatabase(App.Path & "\libraryic.mdb")
Set rs = db.OpenRecordset("Book_Details", dbOpenTable)
''Do While Not Form1.Data1.Recordset.EOF
''Data1.Recordset.MoveNext ‘was trying this method earlier
''While Not Data1.Recordset.EOF
If rs.RecordCount > 0 Then
rs.MoveFirst
While Not rs.EOF()
‘here I want to add the Columns and display all SubItems (DB records)
With BooK_Details
Set li = .ListItems.Add(, , (rs!Acc_No))
li.SubItems(1) = IIf(IsNull(rs!Book_Name), "", rs!Book_Name)
li.SubItems(2) = IIf(IsNull(rs!Author), "", rs!Author)
li.SubItems(3) = IIf(IsNull(rs!Publisher), "", rs!Publisher)
li.SubItems(4) = IIf(IsNull(rs!Stock), "", rs!Stock)
li.SubItems(5) = IIf(IsNull(rs!Rack_No), "", rs!Rack_No)
li.SubItems(6) = IIf(IsNull(rs!Classification_No), "", rs!Classification_No)
End With
rs.MoveNext
Wend
Form7.Show
End If
End Sub
What I have in mind is this… but I am like all mixed up now!!
Acc No | Book Name | Author | Publisher
123 NNNN PP LLLL
234 BBBN YUH bpb
chanthung
Junior Poster in Training
52 posts since Jun 2008
Reputation Points: 10
Solved Threads: 0
Can anyone please make a comment....so that i can go ahead.
Thanks
chanthung
Junior Poster in Training
52 posts since Jun 2008
Reputation Points: 10
Solved Threads: 0