Its a component so you'll need to add it first. Either press CTRL + T or goto project then click components, then search for microsoft common controls, and it should have it.
Its a component so you'll need to add it first. Either press CTRL + T or goto project then click components, then search for microsoft common controls, and it should have it.
In this example, I use ADOCn as my connection object and adoRS as my recordset object. Replace these with your variables.
VB Code:
Private Sub cmdLoadListView_Click()
Dim sSQL As String
Dim lvwItem As ListItem
Set adoRS = New ADODB.Recordset
sSQL = "SELECT name FROM tbl2 "
adoRS.Open sSQL, ADOCn
Do Until adoRS.EOF
Set lvwItem = ListView1.ListItems.Add(, , adoRS.Fields.Item("Name").Value)
Loop
adoRS.Close
Set adoRS = Nothing
End Sub
------------------------------------------------------------------------
The following is the code. Datagrid is working fine. But List view does not show any records.
I would advise you to use Option Explicit. You would have found your error easily. adoRS is not defined, change it into rs. You also forgot a MoveNext.
VB Code:
Private Sub cmdLoadListView_Click()
Dim sSQL As String
Dim lvwItem As ListItem
Set rs = New ADODB.Recordset
sSQL = "SELECT NAME FROM TBL1 "
rs.Open sSQL, db
Do Until [B]rs[/B].EOF
Set lvwItem = ListView1.ListItems.Add(, , rs.Fields.Item("Name").Value)
I would advise you to use Option Explicit. You would have found your error easily. adoRS is not defined, change it into rs. You also forgot a MoveNext.
VB Code:
Private Sub cmdLoadListView_Click()
Dim sSQL As String
Dim lvwItem As ListItem
Set rs = New ADODB.Recordset
sSQL = "SELECT NAME FROM TBL1 "
rs.Open sSQL, db
Do Until [B]rs[/B].EOF
Set lvwItem = ListView1.ListItems.Add(, , rs.Fields.Item("Name").Value)
[B]rs.MoveNext[/B]
Loop
rs.Close
Set rs = Nothing
End Sub
It also does not work. Could you please check my project.
Please help.
Last edited by seema_s; Dec 21st, 2005 at 03:09 AM.
Your code adds to the listview no problems. The only minor adjustment is that you forgot to add the button cmdLoadListView, so the add code never executes. Therefore add the button and call it cmdLoadListView and then click on it and it should work
Fine remove the command button but it should still work. What i wrote means that it will load the listview no matter what and it will also do it if you press the button, but you can remove the button and it should work
Last edited by Andrew G; Dec 21st, 2005 at 06:31 AM.
[/QUOTE]
then it runs when you open the form and when you click on the command button[/QUOTE]
I dont want to use commond button to view the listview. When I open the project it should show automatically all the data in a ListView (lvwReport view). Is it possible?
When I add the code to Form Load, It shows nothing. The following is the code:
Private Sub Form_Load()
Call data_connect
rs.Open "Select * from TBL1", db
Set DataGrid1.DataSource = rs
show_rec
Dim sSQL As String
Dim lvwItem As ListItem
Set rs = New ADODB.Recordset
sSQL = "SELECT [NAME] FROM TBL1 "
rs.Open sSQL, db
Do Until rs.EOF
Set lvwItem = ListView1.ListItems.Add(, , rs.Fields.Item("Name").Value)
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Remove the button, my code will still work and show it on load.
Thanks, Andrew. It was not working because I modified its property to lvwReport. Now I removed it so it is working fine. But could you please for the following querries:
1. How can I view this list in Report View? I think I need to change the code for it.
2. When I click a name in the list it should show in a text box (eg. Text1.Text)
For the report view to work, you need to have at least one column. I've added the column through code, but i you wish to add more, change names etc, rightclick on the listview and goto column headers and change what you need. The following code should work. The parts in bold i have added
VB Code:
Private Sub Form_Load()
Call data_connect
rs.Open "Select * from TBL1", db
Set DataGrid1.DataSource = rs
[B]ListView1.ColumnHeaders.Add[/B]
show_rec
[B]ListView1.View = lvwReport[/B]
cmdLoadListView_Click
End Sub
Public Sub show_rec()
text1 = rs(0)
End Sub
Private Sub cmdLoadListView_Click()
Dim sSQL As String
Dim lvwItem As ListItem
Set rs = New ADODB.Recordset
sSQL = "SELECT NAME FROM TBL1 "
rs.Open sSQL, db
Do Until rs.EOF
Set lvwItem = ListView1.ListItems.Add(, , rs.Fields.Item("Name").Value)
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
End Sub
[B]Private Sub ListView1_ItemClick(ByVal Item As ComctlLib.ListItem)
For the report view to work, you need to have at least
It is marvellous. I have added one more column "CITY" and entered some data into it. But I can not view it. I know there is something to be written in the code but what exactly it should be I dont know.
Can I view the listview in grids as well? If yes, how can I?
Like lstview, I would like the datagrid selected data to be shown in the text box (eg. text2.text).
It does not work. I think the following code also to be modified:
rs.Open sSQL, db
Do Until rs.EOF
Set lvwItem = ListView1.ListItems.Add(, , rs.Fields.Item("Name").Value)
rs.MoveNext
rs.Close
Set rs = Nothing
Loop
Yes it does, but modifying it before you have your SQL statement correct and are returning the correct recordset will result in an error which is why I've not posted the necessary modifications yet.
Have you modified your SQL statement to include CITY? If so, have you run it and not gotten any errors?