Page 1 of 2 12 LastLast
Results 1 to 40 of 60

Thread: List View Control

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2005
    Posts
    570

    List View Control

    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

  2. #2
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Re: List View Control

    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.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2005
    Posts
    570

    Re: List View Control

    Quote Originally Posted by Andrew G
    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,

    I could not find with that name.

  4. #4
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Re: List View Control

    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.)

  5. #5
    Lively Member rush_shri's Avatar
    Join Date
    Dec 2005
    Location
    Pune,India
    Posts
    78

    Re: List View Control

    Increase the width of your General tab. May be it's hidden. In that case right mouse click on general tab and unhide it.
    U KNOW U R INTERNET JUNKIE WHEN U CHAT WITH UR FINGERS NOT FROM MOUTH.

    U KNOW U R INTERNET JUNKIE WHEN UR SPOUSE E-MAIL U 2 CALL U 4 DINNER

    U KNOW U R INTERNET JUNKIE WHEN UR ADDRESS BEGINS WITH http:

    U KNOW U R INTERNET JUNKIE WHEN THE PROGRAM TOLD 2 U HAPPENS 2 B TV PROGRAM.

  6. #6
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Re: List View Control

    Quote Originally Posted by seema_s
    I could not find with that name.
    Hence i don't think he even has it loaded, so increasing the tab width won't do much.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2005
    Posts
    570

    Re: List View Control

    How can I get the data from TBL2 (Table Name) into the List View. Field Name is "Name".

    Please help.

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: List View Control

    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.

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2005
    Posts
    570

    Re: List View Control

    Quote Originally Posted by Hack
    How do you connect to your database? Through ADO code I hope.
    Yes, it is with ADO code.

  10. #10
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: List View Control

    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.
    In this example, I use ADOCn as my connection object and adoRS as my recordset object. Replace these with your variables.
    VB Code:
    1. Private Sub cmdLoadListView_Click()
    2. Dim sSQL As String
    3. Dim lvwItem As ListItem
    4. Set adoRS = New ADODB.Recordset
    5. sSQL = "SELECT name FROM tbl2 "
    6. adoRS.Open sSQL, ADOCn
    7. Do Until adoRS.EOF
    8.     Set lvwItem = ListView1.ListItems.Add(, , adoRS.Fields.Item("Name").Value)
    9. Loop
    10. adoRS.Close
    11. Set adoRS = Nothing
    12. End Sub

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2005
    Posts
    570

    Re: List View Control

    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.
    VB Code:
    1. Private Sub cmdLoadListView_Click()
    2. Dim sSQL As String
    3. Dim lvwItem As ListItem
    4. Set adoRS = New ADODB.Recordset
    5. sSQL = "SELECT name FROM tbl2 "
    6. adoRS.Open sSQL, ADOCn
    7. Do Until adoRS.EOF
    8.     Set lvwItem = ListView1.ListItems.Add(, , adoRS.Fields.Item("Name").Value)
    9. Loop
    10. adoRS.Close
    11. Set adoRS = Nothing
    12. End Sub
    ------------------------------------------------------------------------
    The following is the code. Datagrid is working fine. But List view does not show any records.

    VB Code:
    1. Public db As New ADODB.Connection
    2. Public rs As New ADODB.Recordset
    3.  
    4. Public Sub data_connect()
    5. Dim path As String
    6. path = App.path & "\DBL1.mdb"
    7. db.CursorLocation = adUseClient
    8. db.Open "Provider=microsoft.jet.oledb.4.0;persist security info=false;data source=" & path & ";"
    9. End Sub
    10.  
    11. Private Sub Form_Load()
    12. Call data_connect
    13. rs.Open "Select * from TBL1", db
    14. Set DataGrid1.DataSource = rs
    15. show_rec
    16. End Sub
    17.  
    18. Public Sub show_rec()
    19. Text1 = rs(0)
    20.  
    21. End Sub
    22.  
    23. Private Sub cmdLoadListView_Click()
    24. Dim sSQL As String
    25. Dim lvwItem As ListItem
    26. Set rs = New ADODB.Recordset
    27. sSQL = "SELECT NAME FROM TBL1 "
    28. rs.Open sSQL, db
    29. Do Until adoRS.EOF
    30.     Set lvwItem = ListView1.ListItems.Add(, , rs.Fields.Item("Name").Value)
    31. Loop
    32. rs.Close
    33. Set rs = Nothing
    34. End Sub






    Edit: Fixed [vbcode][/vbcode] tags. - Hack
    Last edited by Hack; Dec 20th, 2005 at 10:24 AM.

  12. #12
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: List View Control

    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?

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2005
    Posts
    570

    Re: List View Control

    Quote Originally Posted by 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?

    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.)

  14. #14
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: List View Control

    Try changing your select query to this
    VB Code:
    1. sSQL = "SELECT [NAME] FROM TBL1 "

  15. #15

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2005
    Posts
    570

    Re: List View Control

    Quote Originally Posted by Hack
    Try changing your select query to this
    VB Code:
    1. sSQL = "SELECT [NAME] FROM TBL1 "
    ----------------------------------------------------------------
    Dear Friend Hack,

    The Datagrid works nice but List View does not show any records.
    Plays help.

    Seema_S
    Attached Images Attached Images  

  16. #16
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926

    Re: List View Control

    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:
    1. Private Sub cmdLoadListView_Click()
    2. Dim sSQL As String
    3. Dim lvwItem As ListItem
    4. Set rs = New ADODB.Recordset
    5. sSQL = "SELECT NAME FROM TBL1 "
    6. rs.Open sSQL, db
    7. Do Until [B]rs[/B].EOF
    8.     Set lvwItem = ListView1.ListItems.Add(, , rs.Fields.Item("Name").Value)
    9.     [B]rs.MoveNext[/B]
    10. Loop
    11. rs.Close
    12. Set rs = Nothing
    13. End Sub
    Frans

  17. #17

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2005
    Posts
    570

    Re: List View Control

    Quote Originally Posted by Frans C
    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:
    1. Private Sub cmdLoadListView_Click()
    2. Dim sSQL As String
    3. Dim lvwItem As ListItem
    4. Set rs = New ADODB.Recordset
    5. sSQL = "SELECT NAME FROM TBL1 "
    6. rs.Open sSQL, db
    7. Do Until [B]rs[/B].EOF
    8.     Set lvwItem = ListView1.ListItems.Add(, , rs.Fields.Item("Name").Value)
    9.     [B]rs.MoveNext[/B]
    10. Loop
    11. rs.Close
    12. Set rs = Nothing
    13. End Sub
    It also does not work. Could you please check my project.

    Please help.
    Attached Files Attached Files
    Last edited by seema_s; Dec 21st, 2005 at 03:09 AM.

  18. #18

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2005
    Posts
    570

    Re: List View Control

    Quote Originally Posted by seema_s
    It also does not work. Could you please check my project.

    Please help.
    I need help but nobody seems to solve my problem.

    seema_s

  19. #19
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Re: List View Control

    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

  20. #20
    Junior Member
    Join Date
    Dec 2005
    Posts
    18

    Re: List View Control

    try this..
    VB Code:
    1. Private Sub cmdLoadListView_Click()
    2. Dim sSQL As String
    3. Dim lvwItem As ListItem
    4. Set rs = New ADODB.Recordset
    5. sSQL = "SELECT [NAME] FROM TBL1 "
    6. rs.Open sSQL, db
    7. Do Until rs.EOF
    8.     Set lvwItem = ListView1.ListItems.Add(, , rs.Fields.Item("Name").Value)
    9.     rs.MoveNext
    10. Loop
    11. rs.Close
    12. Set rs = Nothing
    13. End Sub
    Last edited by yesfriends; Dec 21st, 2005 at 04:58 AM.

  21. #21

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2005
    Posts
    570

    Re: List View Control

    Quote Originally Posted by yesfriends
    try this..
    This is also not working. But there is no error also. Simply the listview is empty.

  22. #22
    Junior Member
    Join Date
    Dec 2005
    Posts
    18

    Re: List View Control

    hi create one command button name cmdLoadListView...at onclick event of this command button write below code..
    VB Code:
    1. Dim sSQL As String
    2. Dim lvwItem As ListItem
    3. Set rs = New ADODB.Recordset
    4. sSQL = "SELECT [NAME] FROM TBL1 "
    5. rs.Open sSQL, db
    6. Do Until rs.EOF
    7.     Set lvwItem = ListView1.ListItems.Add(, , rs.Fields.Item("Name").Value)
    8.     rs.MoveNext
    9. Loop
    10. rs.Close
    11. Set rs = Nothing

  23. #23

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2005
    Posts
    570

    Re: List View Control

    Quote Originally Posted by yesfriends
    hi create one command button name cmdLoadListView...at onclick event of this command button write below code..
    VB Code:
    1. Dim sSQL As String
    2. Dim lvwItem As ListItem
    3. Set rs = New ADODB.Recordset
    4. sSQL = "SELECT [NAME] FROM TBL1 "
    5. rs.Open sSQL, db
    6. Do Until rs.EOF
    7.     Set lvwItem = ListView1.ListItems.Add(, , rs.Fields.Item("Name").Value)
    8.     rs.MoveNext
    9. Loop
    10. rs.Close
    11. 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)?

    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.

  24. #24
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Re: List View Control

    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.

  25. #25

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2005
    Posts
    570

    Re: List View Control

    [/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?

  26. #26
    Junior Member
    Join Date
    Dec 2005
    Posts
    18

    Re: List View Control

    u write this code with form onload event....and when ur form will load then it automatically populate ur list view..
    VB Code:
    1. Dim sSQL As String
    2. Dim lvwItem As ListItem
    3. Set rs = New ADODB.Recordset
    4. sSQL = "SELECT [NAME] FROM TBL1 "
    5. rs.Open sSQL, db
    6. Do Until rs.EOF
    7.     Set lvwItem = ListView1.ListItems.Add(, , rs.Fields.Item("Name").Value)
    8.     rs.MoveNext
    9. Loop
    10. rs.Close
    11. Set rs = Nothing

  27. #27

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2005
    Posts
    570

    Re: List View Control

    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

  28. #28
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Re: List View Control

    Remove the button, my code will still work and show it on load.

  29. #29

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2005
    Posts
    570

    Re: List View Control

    Quote Originally Posted by Andrew G
    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)

    Could you please help me?

    Seema_S

  30. #30
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: List View Control

    Quote Originally Posted by seema_s
    1. How can I view this list in Report View? I think I need to change the code for it.
    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
    2. When I click a name in the list it should show in a text box (eg. Text1.Text)
    VB Code:
    1. Private Sub ListView1_Click()
    2. Text1.Text = ListView1.SelectedItem.Text
    3. End Sub

  31. #31
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Re: List View Control

    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:
    1. Private Sub Form_Load()
    2. Call data_connect
    3. rs.Open "Select * from TBL1", db
    4. Set DataGrid1.DataSource = rs
    5. [B]ListView1.ColumnHeaders.Add[/B]
    6. show_rec
    7. [B]ListView1.View = lvwReport[/B]
    8. cmdLoadListView_Click
    9. End Sub
    10.  
    11. Public Sub show_rec()
    12. text1 = rs(0)
    13.  
    14. End Sub
    15.  
    16. Private Sub cmdLoadListView_Click()
    17. Dim sSQL As String
    18. Dim lvwItem As ListItem
    19. Set rs = New ADODB.Recordset
    20. sSQL = "SELECT NAME FROM TBL1 "
    21. rs.Open sSQL, db
    22. Do Until rs.EOF
    23.     Set lvwItem = ListView1.ListItems.Add(, , rs.Fields.Item("Name").Value)
    24.     rs.MoveNext
    25. Loop
    26. rs.Close
    27. Set rs = Nothing
    28. End Sub
    29. [B]Private Sub ListView1_ItemClick(ByVal Item As ComctlLib.ListItem)
    30. text1.Text = Item.Text
    31. End Sub[/B]

  32. #32

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2005
    Posts
    570

    Re: List View Control

    Quote Originally Posted by Andrew G
    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).

    Sorry for bothering you. But I need help.

    Seema_S

  33. #33
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: List View Control

    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.

  34. #34

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2005
    Posts
    570

    Re: List View Control

    Quote Originally Posted by Hack
    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.

    Set lvwItem = ListView1.ListItems.Add(, , rs.Fields.Item("Name").Value)

  35. #35
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: List View Control

    Quote Originally Posted by seema_s
    The following is the code. But I dont know how to modify it.

    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?

  36. #36

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2005
    Posts
    570

    Re: List View Control

    Quote Originally Posted by Hack
    This is step number two. Have you modified your SQL call to get the CITY information?
    Mr. Hack, I dont know how to modify it.

  37. #37
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: List View Control

    Here is your existing SQL statement
    VB Code:
    1. sSQL = "SELECT NAME FROM TBL1 "
    To include gather CITY, change it to this
    VB Code:
    1. sSQL = "SELECT NAME, CITY FROM TBL1 "
    Nothing else needs to be changed. Now, your recordset will contain two elements instead of just one.

  38. #38

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2005
    Posts
    570

    Re: List View Control

    Quote Originally Posted by Hack
    Here is your existing SQL statement
    VB Code:
    1. sSQL = "SELECT NAME FROM TBL1 "
    To include gather CITY, change it to this
    VB Code:
    1. sSQL = "SELECT NAME, CITY FROM TBL1 "
    Nothing else needs to be changed. Now, your recordset will contain two elements instead of just one.
    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

  39. #39
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: List View Control

    Quote Originally Posted by seema_s
    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?

    We are taking this one step at a time.

  40. #40

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2005
    Posts
    570

    Re: List View Control

    Quote Originally Posted by Hack
    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.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width