-
Apr 14th, 2006, 03:00 PM
#1
Thread Starter
Lively Member
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)
-
Apr 14th, 2006, 03:03 PM
#2
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
-
Apr 14th, 2006, 03:32 PM
#3
Re: Help with Listview:Urgent
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.
-
Apr 14th, 2006, 05:06 PM
#4
Hyperactive Member
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 ).
---------------------
-
Apr 15th, 2006, 09:42 AM
#5
Thread Starter
Lively Member
Re: Help with Listview:Urgent
============================
Plz see this code. I m using this
============================
VB Code:
If lvList.ListItems.count > 0 Then
Dim ANS As Integer
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)
'Me.MousePointer = vbHourglass
If ANS = vbYes Then
Dim i As Integer
For i = 1 To lvList.ListItems.count
If isRecordExist("tblPDC_Manager", "CheckNo", CLng(LeftSplitUF(lvList.ListItems(i).Tag))) = True Then
If lvList.ListItems(i).Checked = True Then
ChangeValue strCon, "tblPDC_Manager", "Cleared", "Y", , "WHERE CheckNo=" & CLng(LeftSplitUF(lvList.ListItems(i).Tag))
End If
End If
Next i
i = 0
MsgBox "Record has been successfully cleared", vbInformation, "Confirm"
End If
ANS = 0
Me.MousePointer = vbDefault
Else
MsgBox "No record to clear.", vbExclamation
End If
-
Apr 15th, 2006, 09:45 AM
#6
Thread Starter
Lively Member
Re: Help with Listview:Urgent
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
-
Apr 15th, 2006, 09:47 AM
#7
Re: Help with Listview:Urgent
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.
-
Apr 15th, 2006, 10:11 AM
#8
Thread Starter
Lively Member
Re: Help with Listview:Urgent
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:
============================================
There are some Procedure i m using ,so try it andhelp me
if any one done it then plzz upload full source code
============================================
'Procedure that will change the value at once
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)
If srcCondition <> vbNullString Then srcCondition = " " & srcCondition
If isNumber = True Then
srcCN.Execute "UPDATE " & srcTable & " SET " & srcField & " =" & srcValue & " " & srcCondition
Else
srcCN.Execute "UPDATE " & srcTable & " SET " & srcField & " ='" & srcValue & "'" & " " & srcCondition
End If
End Sub
'--------------------------------------------------------------
'Function used to check if the record exit or not.
Public Function isRecordExist(ByVal sTable As String, ByVal sField As String, ByVal sStr As String, Optional isString As Boolean) As Boolean
Dim rs As New Recordset
rs.CursorLocation = adUseClient
If isString = False Then
rs.Open "Select * From " & sTable & " Where " & sField & " = " & sStr, strCon, adOpenStatic, adLockOptimistic
Else
rs.Open "Select * From " & sTable & " Where " & sField & " = '" & sStr & "'", strCon, adOpenStatic, adLockOptimistic
End If
If rs.RecordCount < 1 Then
isRecordExist = False
Else
isRecordExist = True
End If
Set rs = Nothing
End Function
'------------------------------------------------------------------
Public Function LeftSplitUF(ByVal srcUF As String) As String
If srcUF = "*~~~~~*" Then LeftSplitUF = "": Exit Function
Dim i As Integer
Dim t As String
For i = 1 To Len(srcUF)
If Mid$(srcUF, i, 7) = "*~~~~~*" Then
Exit For
Else
t = t & Mid$(srcUF, i, 1)
End If
Next i
LeftSplitUF = t
i = 0
t = ""
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.
-
Apr 15th, 2006, 10:31 AM
#9
Re: Help with Listview:Urgent
You can make your code easier to read if you surround the code with VBCode tags as in this example.
[vbcode]
'Your code
[/vbcode]
which will cause it to show up like this.
-
Apr 15th, 2006, 11:26 AM
#10
Thread Starter
Lively Member
Re: Help with Listview:Urgent
-
Apr 15th, 2006, 11:38 AM
#11
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.
-
Apr 15th, 2006, 01:11 PM
#12
Thread Starter
Lively Member
Re: Help with Listview:Urgent
if it possible then plzzzz give me full working code plzzzzzz
-
Apr 15th, 2006, 01:19 PM
#13
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.
-
Apr 15th, 2006, 02:34 PM
#14
New Member
Re: Help with Listview:Urgent
VB Code:
For i = 1 To lvList.ListItems.count
If isRecordExist("tblPDC_Manager", "CheckNo", CLng(LeftSplitUF(lvList.ListItems(i).Tag))) = True Then
If lvList.ListItems(i).Checked = True Then
ChangeValue strCon, "tblPDC_Manager", "Cleared", "Y", , "WHERE CheckNo=" & CLng(LeftSplitUF(lvList.ListItems(i).Tag))
End If
End If
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.
-
Apr 15th, 2006, 06:53 PM
#15
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.
-
Apr 19th, 2006, 02:58 PM
#16
Hyperactive Member
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 ).
---------------------
-
Apr 19th, 2006, 03:10 PM
#17
Hyperactive Member
Re: Help with Listview:Urgent
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|