in the case of 3 LV items it shows:
Debug.Print indx=3
Debug.Print ListView1.ListItems.Count=3
Debug.Print ListView1.ListItems.Count=2
That means, everything is fine
Printable View
Ok so the question is why are you calling it? The code above this call removes an item from the listview. At this point that item would be gone. I can not think of any reason you would need to reload or update the list view. The remove does that for you.
It may be possible that the code to reload the listview is getting executed before the data has actually been removed from the db and as such is being reloaded into the listview after you have removed it. When you do somethign that causes the list view to be loaded again it would be gone as the db delete has happened by then. Also when you set the break point by the time it got to the call the data was deleted from the db so it did not show in the list.
This would be my best guess but I have not studied that code. Try commenting out that line which calls the subroutine and see what happens when you run your program.
So where is that being set?
When I create a copy of listitem new listitem (copy) arrives at the bottom of the list. But... label which keeps value needed for string2klik keeps old value. After that, if I double click on the newly created item it shows error- but not always
It is not the same it is a different var it has to be set somewhere, so where is string2klik being set?
line 221 and line 274 as local variables
I just went back to have a look. The code is very hard to follow. It appears you are calling the click event from the mouse up event. You are also calling it from the double click event. I haven't tested this myself but there is a chance that this could cause the click event to fire twice when you single click and 3 times when you double click.
I see where you set the variables - to subitems(2) Not sure why you are bouncing around using 3 different ways of calling the same query nor am I sure why you are calling the click event in such cases but it makes it very hard to keep track of what is going on and as a result would make it hard to locate your problem.
When your error occurs check the variables and the subitems value to see what they are at the time of the error and maybe that will help.
DataMiser
Yas... the whole module is a little bit messy. Text in bold-italic is quite possible.Quote:
I just went back to have a look. The code is very hard to follow. It appears you are calling the click event from the mouse up event. You are also calling it from the double click event. I haven't tested this myself but there is a chance that this could cause the click event to fire twice when you single click and 3 times when you double click.
As I told before, there's a lot of crap code here. I'm creating database connection in every subroutine and so on... It is easy to correct later but it doesn't influent on program itself. I made some experiments and therefore we have different approaches to the same thing.Quote:
I see where you set the variables - to subitems(2) Not sure why you are bouncing around using 3 different ways of calling the same query nor am I sure why you are calling the click event in such cases but it makes it very hard to keep track of what is going on and as a result would make it hard to locate your problem.
I did that hundred of times already ))))Quote:
When your error occurs check the variables and the subitems value to see what they are at the time of the error and maybe that will help.
But in any case.... with your help I solved the problem related with correct deleting of list item. I didn't pay my attention on that call to subroutine for updating of listview control. It is solved by your help and.... thank you for that!
So what was the results?Quote:
I did that hundred of times already ))))
Quote:
When your error occurs check the variables and the subitems value to see what they are at the time of the error and maybe that will help.
Quote:
I did that hundred of times already ))))
Quote:
So what was the results?
I know the error occurs on that line and I know it is because the query returns no result. What I do not know is what the value of those variables are at the time the error occurs which is what I was referring to when I asked what were the results. Which of course I still do not have an answer.Quote:
When I click slowly on newly added listitem, everything is working fine. If I do that faster, I get error on line 231.
DataMiser
I appreciate your help to me (and not only to me) very much.
You didn't read (I think) at the beginning of this thread that in debugger everything is working fine. Even the previous problem (with refreshing) didn't exist while debugging. When I'm working without debugger I'm getting error at line 231 as I told a few times before.
I can check some variables (if that's needed) and write results here but I simply don't know how to do that if the bug is (obviously) related with single click/double-click routine.
To be honest, I don't have any idea where to put breakpoint in this case. If I put them, the error won't be generated. :confused:
rgds
In your previous post you said
So if the error occurs the code stops on that line and then you can check the value of those variables. This could go a long way to helping find the problem.Quote:
When I click slowly on newly added listitem, everything is working fine. If I do that faster, I get error on line 231.
Seems this bug might be related to event-firing - maybe something is being executed twice or something to that affect.
If it's only happening "when you don't break" - but it does happen when you are running in the IDE - then do this
I am assuming that the "bug moment" manifests itself in the count "not being reduced" in this area of code. Basically check for that "condition" and STOP - that way you only enter a BREAK when the bug is happening.Code:If Trim(ListView1.ListItems(indx).SubItems(2)) = Trim(lblKliknutoNa.Caption) Then
Debug.Print ListView1.ListItems.Count
holdCount = ListView1.ListItems.Count
ListView1.ListItems.Remove (indx)
Debug.Print ListView1.ListItems.Count
If holdCount = ListView1.ListItems.Count Then
Stop
End If
indx = indx - 1
lvredova = lvredova - 1
End If
Then you can inspect your CALL STACK and see what "route" led you to this evil condition.
I beg you for patience, please. I have no idea which variables to check. If you suspect on some of them, please write and I'll do that.
I'm sure that the problem will be solved soon. I'll write in the answer of szlamany's post how I intend to do that.
string2klik = lListItem.SubItems(2) == "receptura CS-5 (kopija) i.e. the correct value
SQL2 gets that value for query i.e., the correct value
txtNaziv.Text = rs22.Fields(4).Value == receptura CS-5 i.e. incorrect (old) value contained in the listitem selected before new double click
szlamany
I have the same opinion and therefore I'll shange code a little bit. I intend to re-write ListView1_dblclick subroutine avoiding to call ListView1_click.Quote:
Seems this bug might be related to event-firing - maybe something is being executed twice or something to that affect.
Debug.Print ListView1.ListItems.Count=3Quote:
If it's only happening "when you don't break" - but it does happen when you are running in the IDE - then do this
I am assuming that the "bug moment" manifests itself in the count "not being reduced" in this area of code. Basically check for that "condition" and STOP - that way you only enter a BREAK when the bug is happening.Code:If Trim(ListView1.ListItems(indx).SubItems(2)) = Trim(lblKliknutoNa.Caption) Then
Debug.Print ListView1.ListItems.Count
holdCount = ListView1.ListItems.Count
ListView1.ListItems.Remove (indx)
Debug.Print ListView1.ListItems.Count
If holdCount = ListView1.ListItems.Count Then
Stop
End If
indx = indx - 1
lvredova = lvredova - 1
End If
Then you can inspect your CALL STACK and see what "route" led you to this evil condition.
holdCount = ListView1.ListItems.Count=2
Stop is not triggered and call stack contains: ListView1_dblclick.
Breakpoint is as usual at : txtNaziv.Text = rs22.Fields(4).Value
My point was to have NO BREAKPOINT - just let the code run.
That's when the error happens right???
If you break you don't get the error you said - right?
You said you needed to click the button fast or something to that affect.
The IF/STOP will cause a BREAK only when a "bad condition" is detected - and you put that condition in the IF statement.
And put the IF/STOP code in whatever place you think the error will manifest.
szlamany
It is a breakpoint made from debugger itself after error occurred.Quote:
My point was to have NO BREAKPOINT - just let the code run.
yesQuote:
That's when the error happens right???
rightQuote:
If you break you don't get the error you said - right?
everything will be clearly explained in the next postQuote:
You said you needed to click the button fast or something to that affect.
Well.... the error is triggered by this code
vb Code:
Set rs22 = New ADODB.Recordset Dim sql2 As String sql2 = "SELECT * FROM baza_receptura WHERE nazvanje = " & Chr$(34) & string2klik & Chr$(34) rs22.Open sql2, con, adOpenDynamic, adLockOptimistic txtNazvanje.Visible = True txtNaziv.Text = rs22.Fields(4).Value txtNaziv.Visible = True
query gets a proper value, opens the connection
but.....
txtNaziv.Text = rs22.Fields(4).Value
after double click keeps an old value (previous one)
This happened only if you double-click newly created listitem inside first 2-3 seconds after its creation. Is it possible that database didn't write new record in database in that 2-3 seconds? And if it is true, how to override that?
P.S. I've realized that line which calls single click event inside of double click event is not the place which produces error.
That is an easy question to answer yourself - right in your code.
Simply do a SELECT in the same routine that is adding the new record. That SELECT coming back with the new record (immediately) will prove that you do not have a timing issue involving the DB.
I follow a very strict hand-shake for DB insert and delete in regard to my UI.
After INSERT I always do a GET to "see real DB record" and display that in my UI.
I think you may need to review the event(s) code for the ListView. You have code for the MouseUp, Click and Double Click events.
When you Double Click, on an item in the ListView, the following events (for which you have code) will be invoked (in this order):
Mouse Up
Click
Double Click
Mouse Up
When you Single Click, on an item in the ListView, the following events (for which you have code) will be invoked (in this order):
Mouse Up
Click
You need to make sure that your logic takes account of this.
Dear friends.... I re-wrote part of code for ListView1_DblClick event and everything works fine now. Instead to call ListView1_Click inside of DblClick I simply copied ListView1_Click code inside DblClick and everything works like a charm! ListView1_DblClick and ListView1_Click are almost the same. The only difference is that ListView1_DblClick calls additional window for data editing. Reducing amount of events was the key for this bug.
I wish to thank DataMiser, szlamany, Doogle, LaVolpe and others who spent their free time to help me with this stupid issue.