Page 2 of 2 FirstFirst 12
Results 41 to 67 of 67

Thread: ListView problem: no refreshing after item deletion

  1. #41

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2012
    Posts
    616

    Re: ListView problem: no refreshing after item deletion

    Quote Originally Posted by szlamany View Post
    Then don't break - but do this instead...

    Put a DEBUG.PRINT statement below the line indicated...

    Code:
            If Trim(ListView1.ListItems(indx).SubItems(2)) = Trim(lblKliknutoNa.Caption) Then
                Debug.Print indx
                Debug.Print ListView1.ListItems.Count
                ListView1.ListItems.Remove (indx)
                Debug.Print ListView1.ListItems.Count
                indx = indx - 1
                lvredova = lvredova - 1
            End If
    what number appears in the immediate window.
    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

  2. #42

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2012
    Posts
    616

    Re: ListView problem: no refreshing after item deletion

    Quote Originally Posted by DataMiser View Post
    As for your other error it means that what you are searching for returned no results. You should always check and see if your query returned results before trying to read the fields of the query. Either you would use recordcount as I have here or test for EOF before accessing the fields.

    Code:
       sql2 = "SELECT * FROM baza_receptura  WHERE nazvanje = " & Chr$(34) & string2klik & Chr$(34)
            rs2.Open sql2, con, adOpenDynamic, adLockOptimistic
            if rs2.recordcount>0 then
                txtNazvanje.Visible = True
                txtNaziv.Text = rs2.Fields(4).Value '>>>DEBUGGER SHOWS EOF ERROR HERE!<<<
                txtNaziv.Visible = True
                txtKomentar.Text = rs2.Fields(5).Value
                txtKomentar.Visible = True
                txtRezultat.Text = ""
           Else
                Msgbox "Record not found"
           End If

    this peace of code isn't a bad idea, generally. This way we can avoid database error. But... what to put instead of Msgbox? How to force the query to return something?

  3. #43
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: ListView problem: no refreshing after item deletion

    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.

  4. #44
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: ListView problem: no refreshing after item deletion

    Quote Originally Posted by Goshx View Post
    this peace of code isn't a bad idea, generally. This way we can avoid database error. But... what to put instead of Msgbox? How to force the query to return something?
    A query will not return something if there is nothing there to return. The question you need to ask yourself is why is it not returning anything.
    Last edited by DataMiser; Mar 3rd, 2012 at 12:09 PM.

  5. #45

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2012
    Posts
    616

    Re: ListView problem: no refreshing after item deletion

    Quote Originally Posted by DataMiser View Post
    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.
    I've never thought about that, to be honest. But you're right. Removing this line of code problem with deleting is solved.


    I have "only" two problems yet ))))

  6. #46

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2012
    Posts
    616

    Re: ListView problem: no refreshing after item deletion

    Quote Originally Posted by DataMiser View Post
    A query will not return something if there is nothing there to return. The question you need to ask yourself is why is it not returning anything.


    Obviously, the parameter (variable) string2klik didn't get new value.

  7. #47
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: ListView problem: no refreshing after item deletion

    So where is that being set?

  8. #48

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2012
    Posts
    616

    Re: ListView problem: no refreshing after item deletion

    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

  9. #49

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2012
    Posts
    616

    Re: ListView problem: no refreshing after item deletion

    Quote Originally Posted by DataMiser View Post
    So where is that being set?
    string2klik is the same as lblKliknutoNa

    here is that place:

    lblKliknutoNa.Caption = frmViewer.ListView1.ListItems(HTI.iItem + 1).SubItems(2)

    I'm using SubItems(2) as the source for queries

  10. #50
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: ListView problem: no refreshing after item deletion

    It is not the same it is a different var it has to be set somewhere, so where is string2klik being set?

  11. #51

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2012
    Posts
    616

    Re: ListView problem: no refreshing after item deletion

    line 221 and line 274 as local variables

  12. #52
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: ListView problem: no refreshing after item deletion

    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.

  13. #53

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2012
    Posts
    616

    Re: ListView problem: no refreshing after item deletion

    DataMiser

    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.
    Yas... the whole module is a little bit messy. Text in bold-italic is quite possible.

    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.
    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.

    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.
    I did that hundred of times already ))))

    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!

  14. #54
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: ListView problem: no refreshing after item deletion

    I did that hundred of times already ))))
    So what was the results?

  15. #55

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2012
    Posts
    616

    Re: ListView problem: no refreshing after item deletion

    Quote Originally Posted by DataMiser View Post
    So what was the results?
    When I click slowly on newly added listitem, everything is working fine. If I do that faster, I get error on line 231.

  16. #56
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: ListView problem: no refreshing after item deletion

    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.
    I did that hundred of times already ))))
    So what was the results?
    When I click slowly on newly added listitem, everything is working fine. If I do that faster, I get error on line 231.
    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.

  17. #57

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2012
    Posts
    616

    Re: ListView problem: no refreshing after item deletion

    Quote Originally Posted by DataMiser View Post
    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.

    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.

    rgds

  18. #58
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: ListView problem: no refreshing after item deletion

    In your previous post you said

    When I click slowly on newly added listitem, everything is working fine. If I do that faster, I get error on line 231.
    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.

  19. #59
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: ListView problem: no refreshing after item deletion

    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

    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.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  20. #60

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2012
    Posts
    616

    Re: ListView problem: no refreshing after item deletion

    Quote Originally Posted by DataMiser View Post
    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.
    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
    Last edited by Goshx; Mar 5th, 2012 at 12:12 PM.

  21. #61

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2012
    Posts
    616

    Re: ListView problem: no refreshing after item deletion

    szlamany

    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.

    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
    Last edited by Goshx; Mar 5th, 2012 at 12:05 PM.

  22. #62
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    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.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  23. #63

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2012
    Posts
    616

    Re: ListView problem: no refreshing after item deletion

    szlamany

    My point was to have NO BREAKPOINT - just let the code run.
    It is a breakpoint made from debugger itself after error occurred.


    That's when the error happens right???
    yes

    If you break you don't get the error you said - right?
    right


    You said you needed to click the button fast or something to that affect.
    everything will be clearly explained in the next post

  24. #64

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2012
    Posts
    616

    Re: ListView problem: no refreshing after item deletion

    Well.... the error is triggered by this code


    vb Code:
    1. Set rs22 = New ADODB.Recordset
    2.         Dim sql2 As String
    3.  
    4.         sql2 = "SELECT * FROM baza_receptura  WHERE nazvanje = " & Chr$(34) & string2klik & Chr$(34)
    5.         rs22.Open sql2, con, adOpenDynamic, adLockOptimistic
    6.        
    7.         txtNazvanje.Visible = True
    8.         txtNaziv.Text = rs22.Fields(4).Value
    9.         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.

  25. #65
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    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.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  26. #66
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    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.
    Last edited by Doogle; Mar 5th, 2012 at 01:40 PM.

  27. #67

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2012
    Posts
    616

    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.

Page 2 of 2 FirstFirst 12

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