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)
Re: Help with Listview:Urgent
Welcome to the Forums.
Moved :)
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.
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
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
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
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.
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:
============================================
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.
'-------------------------------------------------------------------------
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.
Re: Help with Listview:Urgent
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.
Re: Help with Listview:Urgent
if it possible then plzzzz give me full working code plzzzzzz
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.
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.
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.
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?
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"