Results 1 to 30 of 30

Thread: List View (RESOLVED)

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Resolved List View (RESOLVED)

    Can anybody help me out i'm having a few problems with my address book. The problem is on frmDisplay can you help me display each record in a list view with everything in it. I have also attached my code for you to take a look at
    Last edited by Jamie_Garland; Oct 27th, 2006 at 01:20 PM.

  2. #2
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: List View

    Took only a minute to update the cmdDisplay_Click() event.
    Attached Files Attached Files

  3. #3
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: List View

    EDIT: Oh, a solution was already provided.
    Attached Files Attached Files

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: List View (RESOLVED)

    I'm having a problem with the delete code can anyone help me please i ahve attached my project aswell.

    VB Code:
    1. Private Sub cmdDelete_Click()
    2. Dim lngIndex As Long
    3. Dim i As Long
    4.  
    5. If Admin = False Or User = True Then
    6.    
    7.     MsgBox "Sorry, unfortunately only someone with Administrator Access can perform that operation. Please contact your administrator for further queries."
    8.  
    9. Else
    10.  
    11.  
    12. If vbNo = MsgBox("Are you sure?", vbYesNo + vbQuestion, "About to Delete This address") Then
    13.     Exit Sub
    14. End If
    15. For lngIndex = 1 To Number - 1
    16.     With AddressBook(lngIndex)
    17.         .fullname = AddressBook(lngIndex + 1).fullname
    18.         .address = AddressBook(lngIndex + 1).address
    19.         .town = AddressBook(lngIndex + 1).town
    20.         .postcode = AddressBook(lngIndex + 1).postcode
    21.         .dob = AddressBook(lngIndex + 1).dob
    22.         .house = AddressBook(lngIndex + 1).house
    23.         .mobile = AddressBook(lngIndex + 1).mobile
    24.     End With
    25. Next
    26. Kill FileName
    27. Number = Number - 1
    28. Open FileName For Output As #1
    29.  
    30. For i = 1 To Number ' - 1
    31.     With AddressBook(i)
    32.         Write #1, .fullname
    33.         Write #1, .address
    34.         Write #1, .town
    35.         Write #1, .postcode
    36.         Write #1, .dob
    37.         Write #1, .house
    38.         Write #1, .mobile
    39.     End With
    40. Next i
    41. Close #1
    42. 'new
    43. With AddressBook(1)
    44.     Text1.Text = .fullname
    45.     Text2.Text = .address
    46.     Text3.Text = .town
    47.     Text4.Text = .postcode
    48.     Text5.Text = .dob
    49.     Text6.Text = .house
    50.     Text7.Text = .mobile
    51. End With
    52. End If
    53. End Sub

  5. #5
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: List View (RESOLVED)

    Your always deleting the first item in the array cause your starting your "shift" loop there.
    VB Code:
    1. Public Sub ShiftDown(ByVal currpos As Long)
    2. Dim i As Long
    3.  
    4.    If currpos < LBound(AddressBook) Or currpos > UBound(AddressBook)
    5.  
    6.    For i = currpos To UBound(AddressBook) - 1  'start shift at current position
    7.       With AddressBook(i)
    8.          .fullname = AddressBook(i + 1).fullname
    9.          .address = AddressBook(i + 1).address
    10.          .town = AddressBook(i + 1).town
    11.          .postcode = AddressBook(i + 1).postcode
    12.          .dob = AddressBook(i + 1).dob
    13.          .house = AddressBook(i + 1).house
    14.          .mobile = AddressBook(i + 1).mobile
    15.       End With
    16.    Next
    17.    ReDim Preserve AddressBook(UBound(AddressBook) - 1)
    18. End Sub

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: List View (RESOLVED)

    How would i get it to delete the record that i choose instead of deleting the first one.?
    Last edited by Jamie_Garland; Oct 21st, 2006 at 05:55 AM.

  7. #7
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: List View

    You pass currpos to the function I gave you, its an array index where you want to start the deletion.

    If your indices for AddressBook() were 0,1,2,3,4,5 or lower bound zero and upper bound 5 then calling ShiftDown(2) will result with 0,1,3,4,5 (these are previous index values).

    You can then go on as you did before, killing the previous copy of the file and creating a new one from AddressBook().

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: List View

    Im lost now can you put it in to the project

  9. #9
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: List View

    VB Code:
    1. Private Sub cmdDelete_Click()
    2. Dim lngIndex As Long
    3. Dim i As Long
    4.  
    5. If Admin = False Or User = True Then
    6.    
    7.     MsgBox "Sorry, unfortunately only someone with Administrator Access can perform that operation. Please contact your administrator for further queries."
    8.  
    9. Else
    10.  
    11.  
    12. If vbNo = MsgBox("Are you sure?", vbYesNo + vbQuestion, "About to Delete This address") Then
    13.     Exit Sub
    14. End If
    15. 'For lngIndex = 1 To Number - 1
    16. '    With AddressBook(lngIndex)
    17. '        .fullname = AddressBook(lngIndex + 1).fullname
    18. '        .address = AddressBook(lngIndex + 1).address
    19. '        .town = AddressBook(lngIndex + 1).town
    20. '        .postcode = AddressBook(lngIndex + 1).postcode
    21. '        .dob = AddressBook(lngIndex + 1).dob
    22. '        .house = AddressBook(lngIndex + 1).house
    23. '        .mobile = AddressBook(lngIndex + 1).mobile
    24. '    End With
    25. 'Next
    26.  
    27. 'Are you still using nextrec variable for storing array index reference? If so...
    28. Call ShiftDown(nextrec - 1)
    29.  
    30. Kill FileName
    31. Number = Number - 1
    32. Open FileName For Output As #1
    33.  
    34. For i = 1 To Number ' - 1
    35.     With AddressBook(i)
    36.         Write #1, .fullname
    37.         Write #1, .address
    38.         Write #1, .town
    39.         Write #1, .postcode
    40.         Write #1, .dob
    41.         Write #1, .house
    42.         Write #1, .mobile
    43.     End With
    44. Next i
    45. Close #1
    46. 'new
    47. With AddressBook(1)
    48.     Text1.Text = .fullname
    49.     Text2.Text = .address
    50.     Text3.Text = .town
    51.     Text4.Text = .postcode
    52.     Text5.Text = .dob
    53.     Text6.Text = .house
    54.     Text7.Text = .mobile
    55. End With
    56. End If
    57. End Sub
    58.  
    59. Public Sub ShiftDown(ByVal currpos As Long)
    60. Dim i As Long
    61.  
    62.    If currpos < LBound(AddressBook) Or currpos > UBound(AddressBook)
    63.  
    64.    For i = currpos To UBound(AddressBook) - 1  'start shift at current position
    65.       With AddressBook(i)
    66.          .fullname = AddressBook(i + 1).fullname
    67.          .address = AddressBook(i + 1).address
    68.          .town = AddressBook(i + 1).town
    69.          .postcode = AddressBook(i + 1).postcode
    70.          .dob = AddressBook(i + 1).dob
    71.          .house = AddressBook(i + 1).house
    72.          .mobile = AddressBook(i + 1).mobile
    73.       End With
    74.    Next
    75.    ReDim Preserve AddressBook(UBound(AddressBook) - 1)
    76. End Sub

  10. #10

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: List View

    this part of the code comes up red.

    Compile Error

    Syntax error

    VB Code:
    1. If currpos < LBound(AddressBook) Or currpos > UBound(AddressBook)
    Last edited by Jamie_Garland; Oct 21st, 2006 at 01:07 PM.

  11. #11
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: List View

    Forgot the Then part

    If currpos < LBound(AddressBook) Or currpos > UBound(AddressBook) Then Exit Sub

  12. #12

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: List View

    Problem now fixed thank you

  13. #13

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: List View (RESOLVED)

    Do you know howe i can get it so on the list view it shows me how many records there is in a label.

  14. #14
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: List View (RESOLVED)

    Quote Originally Posted by Jamie_Garland
    Do you know howe i can get it so on the list view it shows me how many records there is in a label.
    VB Code:
    1. Label.Caption = UBound(AddressBook) + 1

    Please don't PM me asking for help in your thread.

  15. #15

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: List View (RESOLVED)

    See if i was to double click on the listview how would i beable to show the record thats been clicked on.

  16. #16
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: List View

    Store the array index into listitem.tag

    So on click/dblclick you can access the array index through listview1.selecteditem.tag

  17. #17

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: List View

    im lost now

  18. #18
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: List View

    When your adding items to the listview also include .tag

    VB Code:
    1. Dim lstNew As ListItem
    2.  
    3. Set lstNew = ListView1.ListItems.Add
    4. lstNew.Text =  AddressBook(lngIndex + 1).fullnam
    5. lstNew.Tag = lngIndex + 1  'the array index of AddressBook() entry

    So on double click, the selected listitem supplies the index

    MsgBox AddressBook(Val(ListView1.SelectedItem.Tag)).fullnam
    Last edited by leinad31; Oct 27th, 2006 at 01:00 PM.

  19. #19

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: List View

    This is my ListView code.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub cmdBack_Click()
    4.    Unload Me
    5. End Sub
    6.  
    7. Private Sub cmdClose_Click()
    8.     Unload Me
    9. End Sub
    10.  
    11. Private Sub cmdNext_Click()
    12. If lvwDisplay.SelectedItem.Index < lvwDisplay.ListItems.Count Then
    13.     lvwDisplay.ListItems(lvwDisplay.SelectedItem.Index + 1).Selected = True
    14. Else
    15.     lvwDisplay.ListItems(1).Selected = True
    16. End If
    17.     lvwDisplay.SelectedItem.EnsureVisible
    18.     lvwDisplay.SetFocus
    19. End Sub
    20.  
    21. Private Sub cmdPrev_Click()
    22. If lvwDisplay.SelectedItem.Index < lvwDisplay.ListItems.Count Then
    23.     lvwDisplay.ListItems(lvwDisplay.SelectedItem.Index - 1).Selected = True
    24. Else
    25.     lvwDisplay.ListItems(1).Selected = True
    26. End If
    27.     lvwDisplay.SelectedItem.EnsureVisible
    28.     lvwDisplay.SetFocus
    29. End Sub
    30.  
    31. Private Sub Form_Load()
    32. Label1.Caption = UBound(AddressBook) & " Players In The Database "
    33.  
    34.     CenterMe Me
    35.  
    36. Dim lstAdd As ListItem
    37. Dim i As Long
    38.  
    39.    With lvwDisplay
    40.       .AllowColumnReorder = False
    41.       .FullRowSelect = True
    42.       .HideColumnHeaders = False
    43.       .HideSelection = False
    44.       .LabelEdit = lvwManual
    45.       .MultiSelect = False
    46.       .Sorted = True
    47.       .SortKey = 0
    48.       .View = lvwReport
    49.            
    50.       .ColumnHeaders.Clear
    51.       .ColumnHeaders.Add , , "FULL NAME", 2000
    52.       .ColumnHeaders.Add , , "FULL ADDRESS", 3000
    53.       .ColumnHeaders.Add , , "TOWN", 1200
    54.       .ColumnHeaders.Add , , "POST CODE", 1500
    55.       .ColumnHeaders.Add , , "DATE OF BIRTH", 2000
    56.       .ColumnHeaders.Add , , "HOUSE NUMBER", 2000
    57.       .ColumnHeaders.Add , , "MOBILE NUMBER", 2000
    58.      
    59.       .ListItems.Clear
    60.       For i = LBound(AddressBook) To UBound(AddressBook)
    61.          Set lstAdd = .ListItems.Add
    62.          lstAdd.Text = AddressBook(i).fullname
    63.          lstAdd.SubItems(1) = AddressBook(i).address
    64.          lstAdd.SubItems(2) = AddressBook(i).town
    65.          lstAdd.SubItems(3) = AddressBook(i).postcode
    66.          lstAdd.SubItems(4) = AddressBook(i).dob
    67.          lstAdd.SubItems(5) = AddressBook(i).mobile
    68.          lstAdd.SubItems(6) = AddressBook(i).house
    69.       Next
    70.    End With
    71. End Sub
    72.  
    73. Private Sub lvwDisplay_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)
    74.    If lvwDisplay.SortKey = ColumnHeader.Index - 1 Then
    75.       If lvwDisplay.SortOrder = lvwAscending Then
    76.          lvwDisplay.SortOrder = lvwDescending
    77.       Else
    78.          lvwDisplay.SortOrder = lvwAscending
    79.       End If
    80.    Else
    81.       lvwDisplay.SortKey = ColumnHeader.Index - 1
    82.    End If
    83. End Sub

  20. #20
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: List View

    So what's your existing code for double click? We don't even have an idea what you mean by showing the record.. showing in another form? Showing in textboxes? etc?

    You have to learn to be more informative and don't expect someone will always do most of the coding for you.

  21. #21

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: List View

    I want it to show on another form im sorry i should have been more informative in the future.

  22. #22
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: List View

    VB Code:
    1. Dim oFrm As New YourShowForm
    2.  
    3.    Load oFrm
    4.    With AddressBook(Val(lvwDisplay.SelectedItem.Tag))
    5.       oFrm.txtFullName.Text = .fullnam
    6.       oFrm.txtFullName.Tag = Val(lvwDisplay.SelectedItem.Tag)  'in case you need to know array index in other form
    7.       oFrm.txtAddress.Text = .address
    8.       'etc etc
    9.    End With

  23. #23

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: List View

    What do i do to get it on the new form.

    Do i do this first.

    VB Code:
    1. Private Sub lvwDisplay_DblClick()
    2. frmPeople.Show
    3. End Sub
    Last edited by Jamie_Garland; Oct 26th, 2006 at 05:57 PM.

  24. #24
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: List View

    VB Code:
    1. [b]Private Sub lvwDisplay_DblClick()[/b]
    2.  
    3. Dim oFrm As New YourShowForm
    4.  
    5.    Load oFrm
    6.    With AddressBook(Val(lvwDisplay.SelectedItem.Tag))
    7.       oFrm.txtFullName.Text = .fullnam
    8.       oFrm.txtFullName.Tag = Val(lvwDisplay.SelectedItem.Tag)  'in case you need to know array index in other form
    9.       oFrm.txtAddress.Text = .address
    10.       'etc etc
    11.    End With
    12.    [b]oFrm.Show
    13.  
    14. End Sub[/b]

  25. #25

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: List View

    I'll test this code as soon as i get home.

  26. #26

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: List View

    When i try to double click on one of the records i get an error.

    Run-time error '9':

    Subscript out of range

    here is the code.

    This part is the where is highlighted

    With AddressBook(Val(lvwDisplay.SelectedItem.Tag))

    VB Code:
    1. Private Sub lvwDisplay_DblClick()
    2.     Dim oFrm As New oFrm
    3.    
    4.     Load oFrm
    5.     With AddressBook(Val(lvwDisplay.SelectedItem.Tag))
    6.         oFrm.txtFirst.Text = .fullname
    7.         oFrm.txtFirst.Tag = Val(lvwDisplay.SelectedItem.Tag)
    8.    
    9.     End With
    10.     oFrm.Show
    11. End Sub

  27. #27
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: List View

    * sigh * This is getting frustrating.

    You will get that error if you didn't assign anything to the Tag property, so the Val() function will return zero if Tag has no value... and you declared "Option Base 1" so your arrays have no zero index.. hence "subscript out of range"

    You can also get that error if you assigned wrong indices to the Tag property due to wrong arithmetic.

    Now, DID you include, during adding listitems to the listview, saving the array index to the Tag property like I told you a couple of posts back?!?!?

    Or did you just copy paste post #25 disregarding the instruction to initialize values for the Tag property of the listitems in the listview?

  28. #28

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: List View

    This is the code i use below.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub cmdBack_Click()
    4.    Unload Me
    5. End Sub
    6.  
    7. Private Sub cmdClose_Click()
    8.     Unload Me
    9. End Sub
    10.  
    11. Private Sub cmdNext_Click()
    12. If lvwDisplay.SelectedItem.Index < lvwDisplay.ListItems.Count Then
    13.     lvwDisplay.ListItems(lvwDisplay.SelectedItem.Index + 1).Selected = True
    14. Else
    15.     lvwDisplay.ListItems(1).Selected = True
    16. End If
    17.     lvwDisplay.SelectedItem.EnsureVisible
    18.     lvwDisplay.SetFocus
    19. End Sub
    20.  
    21. Private Sub cmdPrev_Click()
    22. If lvwDisplay.SelectedItem.Index < lvwDisplay.ListItems.Count Then
    23.     lvwDisplay.ListItems(lvwDisplay.SelectedItem.Index - 1).Selected = True
    24. Else
    25.     lvwDisplay.ListItems(1).Selected = True
    26. End If
    27.     lvwDisplay.SelectedItem.EnsureVisible
    28.     lvwDisplay.SetFocus
    29. End Sub
    30.  
    31. Private Sub Form_Load()
    32. Label1.Caption = UBound(AddressBook) & " Players In The Database "
    33.  
    34.     CenterMe Me
    35.  
    36. Dim lstAdd As ListItem
    37. Dim i As Long
    38.  
    39.    With lvwDisplay
    40.       .AllowColumnReorder = False
    41.       .FullRowSelect = True
    42.       .HideColumnHeaders = False
    43.       .HideSelection = False
    44.       .LabelEdit = lvwManual
    45.       .MultiSelect = False
    46.       .Sorted = True
    47.       .SortKey = 0
    48.       .View = lvwReport
    49.            
    50.       .ColumnHeaders.Clear
    51.       .ColumnHeaders.Add , , "FULL NAME", 2000
    52.       .ColumnHeaders.Add , , "FULL ADDRESS", 3000
    53.       .ColumnHeaders.Add , , "TOWN", 1200
    54.       .ColumnHeaders.Add , , "POST CODE", 1500
    55.       .ColumnHeaders.Add , , "DATE OF BIRTH", 2000
    56.       .ColumnHeaders.Add , , "HOUSE NUMBER", 2000
    57.       .ColumnHeaders.Add , , "MOBILE NUMBER", 2000
    58.      
    59.       .ListItems.Clear
    60.       For i = LBound(AddressBook) To UBound(AddressBook)
    61.          Set lstAdd = .ListItems.Add
    62.          lstAdd.Text = AddressBook(i).fullname
    63.          lstAdd.SubItems(1) = AddressBook(i).address
    64.          lstAdd.SubItems(2) = AddressBook(i).town
    65.          lstAdd.SubItems(3) = AddressBook(i).postcode
    66.          lstAdd.SubItems(4) = AddressBook(i).dob
    67.          lstAdd.SubItems(5) = AddressBook(i).mobile
    68.          lstAdd.SubItems(6) = AddressBook(i).house
    69.       Next
    70.    End With
    71. End Sub
    72.  
    73. Private Sub lvwDisplay_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)
    74.    If lvwDisplay.SortKey = ColumnHeader.Index - 1 Then
    75.       If lvwDisplay.SortOrder = lvwAscending Then
    76.          lvwDisplay.SortOrder = lvwDescending
    77.       Else
    78.          lvwDisplay.SortOrder = lvwAscending
    79.       End If
    80.    Else
    81.       lvwDisplay.SortKey = ColumnHeader.Index - 1
    82.    End If
    83. End Sub
    84.  
    85. Private Sub lvwDisplay_DblClick()
    86.     Dim oFrm As New oFrm
    87.    
    88.     Load oFrm
    89.     With AddressBook(Val(lvwDisplay.SelectedItem.Tag))
    90.         oFrm.txtFirst.Text = .fullname
    91.         oFrm.txtFirst.Tag = Val(lvwDisplay.SelectedItem.Tag)
    92.    
    93.     End With
    94.     oFrm.Show
    95.  
    96. End Sub

  29. #29
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: List View

    God, can't you do anything besides copying and pasting? We do your code, we even do the debugging for you.

    And now just understanding instructions, which was explained again and again, to add one line you can't do?!?

    VB Code:
    1. .ListItems.Clear
    2.       For i = LBound(AddressBook) To UBound(AddressBook)
    3.          Set lstAdd = .ListItems.Add
    4.          lstAdd.Text = AddressBook(i).fullname
    5.          [b]lstAdd.Tag = i[/b]
    6.          lstAdd.SubItems(1) = AddressBook(i).address
    7.          lstAdd.SubItems(2) = AddressBook(i).town
    8.          lstAdd.SubItems(3) = AddressBook(i).postcode
    9.          lstAdd.SubItems(4) = AddressBook(i).dob
    10.          lstAdd.SubItems(5) = AddressBook(i).mobile
    11.          lstAdd.SubItems(6) = AddressBook(i).house
    12.       Next

    That's it. that's my last post in this thread.

  30. #30

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: List View

    Thank you sorted now.

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