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

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
commented: thxx 4 the help +1

check out this sample, try it and give your feedback.

Dim str As String
Dim rs As New ADODB.Recordset
Dim li As ListItem

str = "select * from org_master order by org_id"
rs.open str, ADODB.adOpenDynamic, ADODB.adUseClient, ADODB.adLockOptimistic

lvoffice.ListItems.Clear

If rs.RecordCount > 0 Then
    rs.MoveFirst
    While Not rs.EOF()
        With lvoffice
            Set li = .ListItems.Add(, , (rs!org_id))
            li.SubItems(1) = Replace(rs!org_name, Chr(5), ", ")
            li.SubItems(2) = IIf(IsNull(rs!Description), "", Replace(rs!Description, Chr(5), ", "))
        End With
        rs.MoveNext
    Wend
End If

If rs.state = adStateOpen Then rs.Close
Set rs = Nothing

regards
Shouvik

commented: thx 4 the help in making listview +1

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

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

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

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)

[B]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[/B]

also see the snapshot.

regards
Shouvik

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

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

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.

check out the bolded part of your code...i just mentioned the point where the code needs to be modified...

With BooK_Details
    [B]set li = .ListItems.Add(, , (rs!Acc_No))[/B]
End With

get me a feedback if this works out...

regards
Shouvik

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.

see there are many reasons for which you can get error 424...
for example,if u mistyped a control name which is not exist at all in your project aka form....or any dependencies like any external components that you referenced previously in your project but which is not exist presently....you might have uninstalled that from your system.....or you have used some variables in your code for which you haven't mentioned the correct datatype....

according to you....this problem can arise from your listview control....make sure that you typed the correct object name for the lv in your code.....lets say...in the code you have used listview1...make sure that you have the control on your form with object name "listview1".....otherwise the compiler won't recognize that...

or it will be more better...if you posted the actual ping point of your code where you are getting the error....may be post the full code if possible.....coz accroding to the code there is no error at all...but there seems to be some other error in the code...but for that the code needs to supervised...

now the choice is yours....

regards
Shouvik

My actual connection is DSN. so do i have to write the code differently to connect my databse to ListView1..?

whether you use DSN or DSN-Less connection, there is no need to write additional code for connecting lv with the database....just pass the connection string in form_load event, open the connection....make sure the you are using a global connection object....and that's it.....one global connection object will handle connecting to the database and this applies to all databound controls on your form....just make sure that the connection object is opened till you close the project....that's it...nothing else to do...

but you have to make sure that the DSN must exist in the ODBC admin. before you try to connect through your code....and ofcourse the connection string should differ in case of DSN connection rather that DSN-Less connection....

regards
Shouvik

try to remove the :

With BooK_Details
end with

and check the listview column you have.. by right click on the listview then goto properties and insert column as number of your fields loaded in the listview.

^_^

try to remove the :

With BooK_Details
end with

why to remove that??? there is no error at this syntax at all....

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

Can anyone please make a comment....so that i can go ahead.
Thanks

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.