Results 1 to 17 of 17

Thread: Help with Listview:Urgent

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2006
    Posts
    85

    Help with Listview:Urgent

    Hello friends,

    I m vijay from india. I am making a project in vb6 but at
    this movement i am having a problem in list view. The problem is.......


    I am using list view.the listview's check box property is true ,i want
    to delete all record,those are checked or selected in listview but
    records are not deleted from database.i m using Access 2000.so anyone
    can help me. plzzzzzzz


    so plzzzz give ce code for deleting selected record from database as
    well as listview.



    Thankx
    (Vijay)

  2. #2
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,713

    Re: Help with Listview:Urgent

    Welcome to the Forums.

    Moved
    VB/Office Guru™ (AKA: Gangsta Yoda™ )
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    • Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,175

    Re: Help with Listview:Urgent

    Quote Originally Posted by vijay2006
    Hello friends,

    I m vijay from india. I am making a project in vb6 but at
    this movement i am having a problem in list view. The problem is.......


    I am using list view.the listview's check box property is true ,i want
    to delete all record,those are checked or selected in listview but
    records are not deleted from database.i m using Access 2000.so anyone
    can help me. plzzzzzzz


    so plzzzz give ce code for deleting selected record from database as
    well as listview.



    Thankx
    (Vijay)
    Please show the code that you are using to delete the records.

  4. #4
    Hyperactive Member Vishalgiri's Avatar
    Join Date
    Oct 2003
    Location
    India
    Posts
    345

    Re: Help with Listview:Urgent

    A long time ago I had came across this problem, the quick and dirty solution was

    1. copy the list in to a Array
    2. Clear the list
    3. remove the the Item of array like array(4) = ""
    4. if array(i) <> "" then Add item

    the proper solution is long.. so i am now bored of typeing

    You must be getting Item/Index already deleted kind of error

    What happens when you deletes

    Dim i as integer
    For i=0 to List1.Items.Count
    If List1.Items(i).Selected then List1.Items(i).Remove
    next

    I Don't remember the properties of List and proper sytax of vb6 as i am switched to .NET

    See When you removes the item the Indexes of all the below item changes and but var i keep on going so if you have deleted 6th item the item next to it will become the 6th one.

    Now try solving the problem yourself. A Hint is there below this line if you still confused then tell me i will give you complete code select all to see the hint

    Hint: A simple GoTo will do the trick
    Last edited by Vishalgiri; Apr 14th, 2006 at 05:07 PM. Reason: just
    Regards,
    Vishalgiri Goswami
    Gujarat, ( INDIA ).
    ---------------------

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Apr 2006
    Posts
    85

    Re: Help with Listview:Urgent

    ============================
    Plz see this code. I m using this
    ============================
    VB Code:
    1. If lvList.ListItems.count > 0 Then
    2.                 Dim ANS As Integer
    3.                 ANS = MsgBox("Are you sure that you want to clear all the checked records in the list?" & vbCrLf & vbCrLf & "NOTE: This will clear the all the checked records in the list from the due checks.", vbQuestion + vbYesNo)
    4.                 'Me.MousePointer = vbHourglass
    5.                 If ANS = vbYes Then
    6.                     Dim i As Integer
    7.                     For i = 1 To lvList.ListItems.count
    8.                         If isRecordExist("tblPDC_Manager", "CheckNo", CLng(LeftSplitUF(lvList.ListItems(i).Tag))) = True Then
    9.                             If lvList.ListItems(i).Checked = True Then
    10.                                ChangeValue strCon, "tblPDC_Manager", "Cleared", "Y", , "WHERE CheckNo=" & CLng(LeftSplitUF(lvList.ListItems(i).Tag))
    11.                             End If
    12.                         End If
    13.                     Next i
    14.                     i = 0
    15.                    
    16.                     MsgBox "Record has been successfully cleared", vbInformation, "Confirm"
    17.                 End If
    18.                 ANS = 0
    19.                 Me.MousePointer = vbDefault
    20.             Else
    21.                 MsgBox "No record to clear.", vbExclamation
    22.             End If

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Apr 2006
    Posts
    85

    Re: Help with Listview:Urgent

    Quote Originally Posted by Vishalgiri
    A long time ago I had came across this problem, the quick and dirty solution was

    1. copy the list in to a Array
    2. Clear the list
    3. remove the the Item of array like array(4) = ""
    4. if array(i) <> "" then Add item

    the proper solution is long.. so i am now bored of typeing

    You must be getting Item/Index already deleted kind of error

    What happens when you deletes

    Dim i as integer
    For i=0 to List1.Items.Count
    If List1.Items(i).Selected then List1.Items(i).Remove
    next

    I Don't remember the properties of List and proper sytax of vb6 as i am switched to .NET

    See When you removes the item the Indexes of all the below item changes and but var i keep on going so if you have deleted 6th item the item next to it will become the 6th one.

    Now try solving the problem yourself. A Hint is there below this line if you still confused then tell me i will give you complete code select all to see the hint

    Hint: A simple GoTo will do the trick
    Ya this is right but i want to delete record from database which is chacked in the listview if u have a proper solution then plzzzz help

  7. #7

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Apr 2006
    Posts
    85

    Re: Help with Listview:Urgent

    Quote Originally Posted by MartinLiss
    What does the ChangeValue sub/function look like? I guess I'll also need to know what data is in the Tags.

    BTW I edited your post and added VBCode tags to make it easier to read.
    VB Code:
    1. ============================================
    2. There are some Procedure i m using ,so try it andhelp me
    3. if any one done it then plzz upload full source code
    4. ============================================
    5. 'Procedure that will change the value at once
    6. Public Sub ChangeValue(ByRef srcCN As Connection, ByVal srcTable As String, ByVal srcField As String, ByVal srcValue As String, Optional isNumber As Boolean, Optional srcCondition As String)
    7.     If srcCondition <> vbNullString Then srcCondition = " " & srcCondition
    8.     If isNumber = True Then
    9.         srcCN.Execute "UPDATE " & srcTable & " SET " & srcField & " =" & srcValue & " " & srcCondition
    10.     Else
    11.         srcCN.Execute "UPDATE " & srcTable & " SET " & srcField & " ='" & srcValue & "'" & " " & srcCondition
    12.     End If
    13. End Sub
    14.  
    15. '--------------------------------------------------------------
    16. 'Function used to check if the record exit or not.
    17. Public Function isRecordExist(ByVal sTable As String, ByVal sField As String, ByVal sStr As String, Optional isString As Boolean) As Boolean
    18.     Dim rs As New Recordset
    19.  
    20.     rs.CursorLocation = adUseClient
    21.     If isString = False Then
    22.         rs.Open "Select * From " & sTable & " Where " & sField & " = " & sStr, strCon, adOpenStatic, adLockOptimistic
    23.     Else
    24.         rs.Open "Select * From " & sTable & " Where " & sField & " = '" & sStr & "'", strCon, adOpenStatic, adLockOptimistic
    25.     End If
    26.     If rs.RecordCount < 1 Then
    27.         isRecordExist = False
    28.     Else
    29.         isRecordExist = True
    30.     End If
    31.     Set rs = Nothing
    32. End Function
    33. '------------------------------------------------------------------
    34. Public Function LeftSplitUF(ByVal srcUF As String) As String
    35.     If srcUF = "*~~~~~*" Then LeftSplitUF = "": Exit Function
    36.     Dim i As Integer
    37.     Dim t As String
    38.     For i = 1 To Len(srcUF)
    39.         If Mid$(srcUF, i, 7) = "*~~~~~*" Then
    40.             Exit For
    41.         Else
    42.             t = t & Mid$(srcUF, i, 1)
    43.         End If
    44.     Next i
    45.     LeftSplitUF = t
    46.     i = 0
    47.     t = ""
    48. End Function
    '-------------------------------------------------------------------------
    Plzzz check this code and help me. I am making a project Health club management system ,If will complete this project then i will upload it here and every one go through and find the error in project then i will correct the error and make a perfact project.

    thankx Friends for supporting me.

    '-------------------------------------------------------------------------
    Last edited by vijay2006; Apr 15th, 2006 at 10:57 AM.

  9. #9

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Apr 2006
    Posts
    85

    Re: Help with Listview:Urgent

    PLZZZZZ help

  11. #11
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,175

    Re: Help with Listview:Urgent

    Put a breakpoint on the ChangeValue strCon, "tblPDC_Manager"... line and trace the code (line by line) by pressing F8 multiple times. At some point you will see the code flow diverge from where you expect it to go. You can also examine the values of the variables in each line you come to.

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Apr 2006
    Posts
    85

    Re: Help with Listview:Urgent

    if it possible then plzzzz give me full working code plzzzzzz

  13. #13
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,175

    Re: Help with Listview:Urgent

    I doubt if anyone could tell what is wrong by just looking at the code. In case you don't know how to debug, what you do is to put the mouse in the margin to the left of the line that I mentioned and click the mouse. That will place a red dot there which is a breakpoint. Run the code and it will stop there since I assume that that line isn't being skipped. Then press F8 one line at a time and see where the code goes.

  14. #14
    New Member
    Join Date
    Apr 2006
    Posts
    2

    Re: Help with Listview:Urgent

    VB Code:
    1. For i = 1 To lvList.ListItems.count
    2.                         If isRecordExist("tblPDC_Manager", "CheckNo", CLng(LeftSplitUF(lvList.ListItems(i).Tag))) = True Then
    3.                             If lvList.ListItems(i).Checked = True Then
    4.                                ChangeValue strCon, "tblPDC_Manager", "Cleared", "Y", , "WHERE CheckNo=" & CLng(LeftSplitUF(lvList.ListItems(i).Tag))
    5.                             End If
    6.                         End If
    7.                     Next i
    ithink there are some internal problem becose the code is give not any error but in this code the program is not come in to the for loop so problem in loop .If any one solve this problem then write the solution here.

  15. #15
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,175

    Re: Help with Listview:Urgent

    I have two questions for you:

    1) Why are you using two different member names?

    2) Do you understand what I was trying to explain concerning breakpoints?

    If you can answer yes to the second question why not put a breakpoint someplace where you know the code goes and step throught (F8) the code from there. That the ONLY way this problem will be solved.

  16. #16
    Hyperactive Member Vishalgiri's Avatar
    Join Date
    Oct 2003
    Location
    India
    Posts
    345

    Re: Help with Listview:Urgent

    This time I am not Agree with my MartinLiss (he is like my Elder Brother).

    I have too much respect for MartinLiss but If Vijay Would know how to debug and do some of the trick you mentioned then why he would be here to ask questions?
    Regards,
    Vishalgiri Goswami
    Gujarat, ( INDIA ).
    ---------------------

  17. #17
    Hyperactive Member Vishalgiri's Avatar
    Join Date
    Oct 2003
    Location
    India
    Posts
    345

    Re: Help with Listview:Urgent

    Quote Originally Posted by vijay2006
    Ya this is right but i want to delete record from database which is chacked in the listview if u have a proper solution then plzzzz help
    See when you removes the selected records from listbox at that time Fire some query to delete that specific record from database.

    I hope you know SQL.


    And one more thing, You should not use two diffrent member names, if your password is lost then you can get it mailed.

    Also Can't you understand MartinLiss have told you many times that use vbcode tag.

    This is very disapointing yaar, As an Indian we are the Gurus of Programming, and you are bluring the image of the Great Indian Programmers.

    So be carefull next time we are always here to help you but No one will do anything for you, ya we can help you. But Keep in mind "there are no free lunches in the world"
    Regards,
    Vishalgiri Goswami
    Gujarat, ( INDIA ).
    ---------------------

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