Dear Friends,
How can I get a list view control to put on a form? I can not see such control. Please help.
Seema_S
Printable View
Dear Friends,
How can I get a list view control to put on a form? I can not see such control. Please help.
Seema_S
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.
Friend,Quote:
Originally Posted by Andrew G
I could not find with that name.
oops sorry its actually Microsoft Windows Common Controls 5.0 (there is also 6.0 which has more options but you can't add XP styls to it.)
Increase the width of your General tab. May be it's hidden. In that case right mouse click on general tab and unhide it.
Hence i don't think he even has it loaded, so increasing the tab width won't do much.Quote:
Originally Posted by seema_s
How can I get the data from TBL2 (Table Name) into the List View. Field Name is "Name".
Please help.
How do you connect to your database? Through ADO code I hope.Quote:
Originally Posted by seema_s
Yes, it is with ADO code.Quote:
Originally Posted by Hack
In this example, I use ADOCn as my connection object and adoRS as my recordset object. Replace these with your variables.Quote:
Originally Posted by seema_s
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
------------------------------------------------------------------------Quote:
Originally Posted by Hack
The following is the code. Datagrid is working fine. But List view does not show any records.
VB Code:
Public db As New ADODB.Connection Public rs As New ADODB.Recordset Public Sub data_connect() Dim path As String path = App.path & "\DBL1.mdb" db.CursorLocation = adUseClient db.Open "Provider=microsoft.jet.oledb.4.0;persist security info=false;data source=" & path & ";" End Sub Private Sub Form_Load() Call data_connect rs.Open "Select * from TBL1", db Set DataGrid1.DataSource = rs show_rec 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 adoRS.EOF Set lvwItem = ListView1.ListItems.Add(, , rs.Fields.Item("Name").Value) Loop rs.Close Set rs = Nothing End Sub
Edit: Fixed [vbcode][/vbcode] tags. - Hack
Is Name the name of your field in the table?
Does it contain a bunch of records?
Are you getting any errors when you run the listview code?
Quote:
Originally Posted by Hack
It doesn't show any error. But I cannot view any data in the list View.
NAME (This is the field name in my database and it has only one field.)
Try changing your select query to thisVB Code:
sSQL = "SELECT [NAME] FROM TBL1 "
----------------------------------------------------------------Quote:
Originally Posted by Hack
Dear Friend Hack,
The Datagrid works nice but List View does not show any records.
Plays help.
Seema_S
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.Quote:
Originally Posted by Frans C
Please help.
I need help but nobody seems to solve my problem.Quote:
Originally Posted by seema_s
seema_s
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
try this..
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 rs.EOF Set lvwItem = ListView1.ListItems.Add(, , rs.Fields.Item("Name").Value) rs.MoveNext Loop rs.Close Set rs = Nothing End Sub
This is also not working. But there is no error also. Simply the listview is empty.Quote:
Originally Posted by yesfriends
hi create one command button name cmdLoadListView...at onclick event of this command button write below code..
VB Code:
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
Yeah, it is working fine. But please let me know why can't we view the contents without using the commond button (like datagrid)?Quote:
Originally Posted by yesfriends
How can I view it in a lvwReport view. I have modified LISTVIEW property to 3 lvwReoprt. But now I can not view any data?
Please help.
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
[/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?
u write this code with form onload event....and when ur form will load then it automatically populate ur list view..
VB Code:
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
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
End Sub
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:Quote:
Originally Posted by Andrew G
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)
Could you please help me?
Seema_S
lvwReport is the only way I ever use a ListView, and that code that I gave you came straight out of a working project.Quote:
Originally Posted by seema_s
Quote:
Originally Posted by seema_s
VB Code:
Private Sub ListView1_Click() Text1.Text = ListView1.SelectedItem.Text End Sub
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) text1.Text = Item.Text End Sub[/B]
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.Quote:
Originally Posted by Andrew G
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).
Sorry for bothering you. But I need help.
Seema_S
If you want to view City, then you need to SELECT city, so add CITY to your SQL select statement which will put both NAME and CITY in your recordset.
The following is the code. But I dont know how to modify it.Quote:
Originally Posted by Hack
Set lvwItem = ListView1.ListItems.Add(, , rs.Fields.Item("Name").Value)
This is step number two. Have you modified your SQL call to get the CITY information?Quote:
Originally Posted by seema_s
Mr. Hack, I dont know how to modify it.Quote:
Originally Posted by Hack
Here is your existing SQL statementTo include gather CITY, change it to thisVB Code:
sSQL = "SELECT NAME FROM TBL1 "Nothing else needs to be changed. Now, your recordset will contain two elements instead of just one.VB Code:
sSQL = "SELECT NAME, CITY FROM TBL1 "
It does not work. I think the following code also to be modified:Quote:
Originally Posted by Hack
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.Quote:
Originally Posted by seema_s
Have you modified your SQL statement to include CITY? If so, have you run it and not gotten any errors?
We are taking this one step at a time.
I have modified the SQL statement but i could not get the data for CITY column.Quote:
Originally Posted by Hack