Re: ListView problem: no refreshing after item deletion
szlamany
Quote:
Seems this bug might be related to event-firing - maybe something is being executed twice or something to that affect.
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:
If it's only happening "when you don't break" - but it does happen when you are running in the IDE - then do this
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
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.
Then you can inspect your CALL STACK and see what "route" led you to this evil condition.
Debug.Print ListView1.ListItems.Count=3
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
Re: ListView problem: no refreshing after item deletion
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.
Re: ListView problem: no refreshing after item deletion
szlamany
Quote:
My point was to have NO BREAKPOINT - just let the code run.
It is a breakpoint made from debugger itself after error occurred.
Quote:
That's when the error happens right???
yes
Quote:
If you break you don't get the error you said - right?
right
Quote:
You said you needed to click the button fast or something to that affect.
everything will be clearly explained in the next post
Re: ListView problem: no refreshing after item deletion
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.
Re: ListView problem: no refreshing after item deletion
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.
Re: ListView problem: no refreshing after item deletion
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.
Re: ListView problem: no refreshing after item deletion
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.