Page 1 of 2 12 LastLast
Results 1 to 40 of 67

Thread: ListView problem: no refreshing after item deletion

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2012
    Posts
    616

    ListView problem: no refreshing after item deletion

    I’ve spent whole 3 days to resolve a problem in my program. I still didn’t do that and therefore I decided to ask here for help.

    -My program have TreeView and ListView control. After selecting an item from TreeView, program fills ListView up from database.
    -ListView has right-click context menu with options for adding a copy of existing item and deleting an item from ListView and from database itself.

    Everything works fine except two things:

    1. When I’m deleting a listview item, it is wiped out from the database but it is still shown as a ListView item. If I change selected item from TreeView and come back to the previous one, the item from ListView is deleted. Also, if I’m working in debugging mode, everything’s working fine.

    I’ve tried many things to resolve this issue without success.

    2. The second problem is related with adding a copy of existing item to the database. It works fine for the first attempt of copying But, if I click new formed item with mouse, I’m getting an error: 3021: Either BOF or EOF is true.. etc etc… I’m not sure why I get this message if I only click on new item which is exactly a copy of an existing item?

    Any help would be helpful
    rgds


    Here's a code which updates ListView from database:

    VB Code:
    1. Public Sub UpdateMainLV()
    2. 'subroutine updates ListView control from database
    3.  
    4.     Dim con33 As ADODB.Connection
    5.     Dim rs33  As ADODB.Recordset
    6.  
    7.     Set con33 = New ADODB.Connection
    8.     con33.CursorLocation = adUseClient
    9.     con33.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db.mdb"
    10.     Set rs33 = New ADODB.Recordset
    11.  
    12.     frmViewer.ListView1.ListItems.Clear ''==============
    13.    
    14.     Dim SQL33 As String
    15.     SQL33 = "SELECT * FROM base_rec WHERE sub_cat = " & "'" & frmViewer.TreeView1.SelectedItem.Text & "'" & " AND lv_category= " & "'" & frmViewer.TreeView1.SelectedItem.Parent.Text & "' ORDER BY sub_cat DESC;"
    16.     rs33.Open SQL33, con33, 3, 4
    17.     rs33.MoveFirst
    18.    
    19.     Dim i As Integer
    20.  
    21.     For i = 0 To rs33.RecordCount - 1
    22.         Set lvwItem = frmViewer.ListView1.ListItems.Add(1, , rs33.Fields!lv_category)
    23.         lvwItem.SubItems(1) = rs33.Fields!sub_cat
    24.         lvwItem.SubItems(2) = rs33.Fields!lvp_name
    25.         lvwItem.SubItems(3) = rs33.Fields!comment
    26.         lvwItem.SubItems(4) = rs33.Fields!date
    27.         rs33.MoveNext
    28.     Next i
    29.  
    30.     rs33.Resync
    31.     rs33.Close
    32.     con33.Close
    33.     Set rs33 = Nothing
    34.     Set con33 = Nothing
    35.    
    36.     frmViewer.ListView1.Refresh

    And here's a code which calls this routine :


    VB Code:
    1. Private Sub mnulvDelete_click() '<============== BRISI LV ITEM
    2.  
    3.     Dim con         As ADODB.Connection
    4.     Dim rs7         As ADODB.Recordset
    5.  
    6.  
    7.     Dim SQL7 As String
    8.     SQL7 = "SELECT * FROM base_rec WHERE lvp_name='" & CStr(lblSel.Caption) & "';"
    9.  
    10.     Set con = New ADODB.Connection
    11.     con.CursorLocation = adUseClient
    12.     con.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db.mdb"
    13.     Set rs7 = New ADODB.Recordset
    14.     rs7.Open SQL7, con, 3 , 4
    15.            
    16.     rs7.Delete
    17.    
    18.     rs7.Update
    19.     rs7.Resync
    20.     rs7.Close
    21.  
    22.  
    23.     Dim indx As Integer
    24.     Dim lvrows As Integer
    25.  
    26.     lvrows = ListView1.ListItems.Count
    27.     For indx = 1 To lvrows
    28.         If indx > lvrows Then Exit For
    29.  
    30.         If Trim(ListView1.ListItems(indx).SubItems(2)) = Trim(lblKliknutoNa.Caption) Then
    31.             ListView1.ListItems.Remove (indx)
    32.             indx = indx - 1
    33.             lvrows = lvrows- 1
    34.         End If
    35.    Next
    36.  
    37. Call frmKV.UpdateMainLV
    38.  
    39. End Sub

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: ListView problem: no refreshing after item deletion

    For the 1st problem, you are querying your DB for lblSel.Caption, but in the listview you are looking for lblKliknutoNa.Caption. If they are not the same, you either won't delete anything or delete the wrong thing from the listview

    For the 2nd problem, I am just assuming your recordset doesn't include the new item. You are clicking on the new item which isn't in the current recordset? You may need to refresh the recordset. If still a problem, we'd probably need to see code that selects items in the db based on listivew selection
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2012
    Posts
    616

    Re: ListView problem: no refreshing after item deletion

    LaVolpe, thank you for the response!
    I'll try to explain a bit


    For the 1st problem, you are querying your DB for lblSel.Caption, but in the listview you are looking for lblKliknutoNa.Caption. If they are not the same, you either won't delete anything or delete the wrong thing from the listview
    lblSel.Caption ih sere instead of a global variable. It contains a ListView subitem value which is used for selecting of item which has to be deleted.
    I've already told that this code works, but it works only if you change TreeView selected item to some other TV item and then move back to the item which selects LV items on the place where we previously deleted our LV item. It also works when we are in debugging mode. A bit strange, isn't it?

    For the 2nd problem, I am just assuming your recordset doesn't include the new item. You are clicking on the new item which isn't in the current recordset? You may need to refresh the recordset. If still a problem, we'd probably need to see code that selects items in the db based on listivew selection
    Subroutine for creating of a copy is quite similar to the routine for deleting

    VB Code:
    1. Private Sub mnulvCopy_click()  '<============== COPY A LV ITEM
    2.  
    3.     Dim con          As ADODB.Connection
    4.     Dim rs6          As ADODB.Recordset
    5.     Dim rs6pom       As ADODB.Recordset
    6.  
    7.     Dim i            As Integer
    8.  
    9.  
    10.     Dim SQL6 As String
    11.     SQL6 = "SELECT * FROM baza_receptura WHERE lvp_name ='" & CStr(lblSel.Caption) & "';"
    12.     Set con = New ADODB.Connection
    13.     con.CursorLocation = adUseClient
    14.     con.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db.mdb"
    15.     Set rs6 = New ADODB.Recordset
    16.     rs6.Open SQL6, con, 3 , 4
    17.        
    18.            
    19.     Set rs6pom = rs6.Clone
    20.     rs6pom.AddNew
    21.            
    22.     For i = 1 To rs6.Fields.Count - 1
    23.         rs6pom(i) = rs6(i)
    24.     Next i
    25.            
    26.     Dim lenstr As Integer
    27.     lenstr = Len(rs6.Fields(4).Value)
    28.    
    29.  
    30.  
    31.     If InStr(lenstr - 7, rs6.Fields(4).Value, " (copy)", vbTextCompare) = 0 Then
    32.     rs6pom.Fields(4).Value = rs6.Fields(4).Value & " (copy)"
    33.  
    34.     rs6pom.Update
    35.     rs6pom.Close
    36.    
    37.     Else
    38.     MsgBox "Only one instance allowed!"
    39.     End If
    40.  
    41.     rs6.Update
    42.     rs6.Resync
    43.     rs6.Close
    44.  
    45.     Call frmKV.UpdateMainLV

    We are cloning selected LV item to a new one. That's the main difference.

    As you can see, there's no code for selecting LV items (that code is working fine). This subroutine creates a new DB record and invites frmKV.UpdateMainLV suboutine (shown above) which reads records again and create ListView items. It works but as I said, if you make selection with mouseclick it shows an error that we reached BOF or EOF.

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: ListView problem: no refreshing after item deletion

    Quote Originally Posted by Goshx View Post
    LaVolpe, thank you for the response...

    I've already told that this code works, but it works only if...
    If it only works in some cases, then your code does not work. When something works sometimes and not all times, you have a logic bug.

    Looking at your code in post #1, the only way a listview item will be deleted is if .SubItems(2) matches that lblKliknutoNa.Caption label. So, I'd assume it doesn't match which means you are changing it elsewhere or it doesn't hold the value you are expecting

    P.S. Your loop can be less complicated by doing it in reverse. You don't have to keep track of index or count and other code you added to avoid errors within the loop
    Code:
    For indx = ListView1.ListItems.Count To 1 Step -1
    ...
    Next
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2012
    Posts
    616

    Re: ListView problem: no refreshing after item deletion

    .SubItems(2) always matches. That's for sure. It gets value from LV and ask for a record in my database.

    I only can't understand why LV control make changes (in the cese of deletion) after we change focus on some other data and after that we come back. This is a kind of mystery for me. Why not immediately? Why after a "walk"? Why it works during debugging?

    That only means that LV isn't refreshed correctly. But I honestly don't know how to refresh it on some other way.





    Second problem (with copying)

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: ListView problem: no refreshing after item deletion

    Maybe there is some confusion on my part? Which listview is not "updating" correctly? I may have been concentrating on the wrong code portion
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

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

    Re: ListView problem: no refreshing after item deletion

    In your mnulvDelete_Click event, having deleted a record from the Table, you are going to all the trouble of deleting the item from the listview and then completely refreshing the ListView in UpdateMainLV which seems to be a waste of time. I suspect you should do one or the other not both.

    EDIT: Just read LaVolpe's last post; I am also assuming that there is only 1 Listview involved, as per your original post - is that a correct assumption?

    Also, I would use the SQL 'DELETE FROM' statement.
    This code
    Code:
        SQL7 = "SELECT * FROM base_rec WHERE lvp_name='" & CStr(lblSel.Caption) & "';"
    
        Set con = New ADODB.Connection
        con.CursorLocation = adUseClient
        con.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db.mdb"
        Set rs7 = New ADODB.Recordset
        rs7.Open SQL7, con, 3 , 4
                
        rs7.Delete
        
        rs7.Update
        rs7.Resync
        rs7.Close
    can be replaced by
    Code:
        Set con = New ADODB.Connection
        con.CursorLocation = adUseClient
        con.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db.mdb"
        SQL7 = "DELETE FROM base_rec WHERE lvp_name='" & CStr(lblSel.Caption) & "';"
        con.Execute SQL7
    and then use LaVolpe's suggestion for locating the listview item(s) to delete or just re-populate the ListView.

    EDIT 2: Your original code to delete will only delete the first record returned from the SELECT, in the case of a 'copied' record, since you're not using an 'ORDER BY' clause the first record could be the original or the copy - this depends entirely on the mood of the Database System, one day it might be the original and on another the copy. The DELETE FROM I am suggesting will delete all records matching the selection criteria, so it may or may not be what you want.

    Picking up on the point made by LaVolpe, you should be consistant with your selection criteria. In one routine you are using the selected treeview item and in the other you're using the contents of a label. If those two do get out of step you're going to have all sorts of problems. Why run the risk? just use one or the other.

    As for creating a copy of an existing record, I'm not sure what value cloning the recordset is adding. The cloning process effectively creates a 'linked copy' of the recordset and its contents, you are then doing it manually in a For / Next loop. Why not just add a copy of the record to the original recordset? I suspect your second problem is associated with closing the cloned recordset which I believe will also close the recordset it was cloned from, thus when you try to perform the Update on the original recordset it has been closed, giving you the error.

    There also seems to be a logic problem in the copying process. You are assuming that only one record will be returned from the selection, whereas later on you are checking whether the record is already a copy. Since you're not using an ORDER BY clause, you're in danger of creating multiple copies of the same record. eg you may have two records thus:
    .... .... abcd efgh
    .... .... abcd efgh (copy)
    you will then test the first record to see if it's a copy; as it isn't you'll add .... .... abcd efgh (copy) again bacause you're not checking if more than one record has been returned.
    Last edited by Doogle; Feb 10th, 2012 at 11:30 PM.

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2012
    Posts
    616

    Re: ListView problem: no refreshing after item deletion

    Well, if someone is interested in, I can send source on e-mail address (plz write me on PM). Many things which you mentioned above is more the question of syntax. I know, it is a bit hard to discuss about some topic if you can't see the whole program.

    So, the best solution is to see the whole program (more precise, it is just a part of a bigger program) and assure yourself how it is working. After that we can publish working code which can help to the people with a similar problem.
    Last edited by Goshx; Feb 11th, 2012 at 12:41 PM.

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2012
    Posts
    616

    Re: ListView problem: no refreshing after item deletion

    Doogle

    I've tried your suggestions with ORDER BY, didn't help ((((

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2012
    Posts
    616

    Re: ListView problem: no refreshing after item deletion

    I still think that the problem is with the database, not with ListView itself. Program works with only one record in the recordset and possibly that produces errors after adding or deleting. I'm not quite sure how to solve this problem because I didn't work with only one record before. EOF is triggered because of that.

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2012
    Posts
    616

    Re: ListView problem: no refreshing after item deletion

    I already told, it is impossible o solve this problem without to se how it works. Therefore I uploaded source for the module together with its database.

    http://www.mediafire.com/?73mjm9911kcz2j2

    I ho[e that we'll finally be able to find that stupid bug.

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

    Re: ListView problem: no refreshing after item deletion

    @Goshx - I am not sure why you decided to PM me for assistance!

    You have two highly invested people assisting you already - and they are asking questions and making suggestions but seems you aren't "in tune" with what they are saying.

    Are you comfortable using DEBUG and stepping through code - examining your variables and what not?

    Have you ever used DEBUG.PRINT to write execution trace details to the debug window to assist you in seeing what's happening as your code runs?

    Not too many people are willing to download someones project and run it - we are all pretty much interested in seeing a code snippet that isn't working and helping you get that working.

    You have a lot of debugging and tracing to do yourself IMO...

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

  13. #13
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: ListView problem: no refreshing after item deletion

    As pointed out earlier one of your problems is here
    Code:
        SQL7 = "SELECT * FROM base_rec WHERE lvp_name='" & CStr(lblSel.Caption) & "';"
    
       
            If Trim(ListView1.ListItems(indx).SubItems(2)) = Trim(lblKliknutoNa.Caption) Then
                ListView1.ListItems.Remove (indx)
    You are deleting an item from the database based on one critera and then removing an item from the list view based on another. The item does not dissappear from the list because you must not be using the right value. It dissappears after the listview has been reloaded because it no longer exists in the database.

    As to the second problem I do not see any code for when you click on the listview so I am not sure what could be going on there.

    A few tips:
    There is no need to move to the first record after opening a recordset. It will be at the first record already.

    When looping through an entire recordset rather than
    Code:
        For i = 0 To rs33.RecordCount - 1
            
            rs33.MoveNext
        Next i
    Use
    Code:
    Do While Not rs33.EOF
         rs33.MoveNext
    Loop
    Recordcount is not available in some cases. The loop above will always work, will be slightly faster and will use slightly less memory.

    You do not need to create 33 different connection and recordset objects. From the looks of things you are only using these recordsets locally which means you could use the same name wihtout needing to add the numbers on each.

    No point in calling resync in most of these cases especially when you are closing the recordset on the next line.

    No need to call .Update after a .Delete .Update is used to add or edit a record.

    When setting a connection string better to create a public variable and set the string once in your form load then reference the variable everywhere else. This way if for any reason you need to change the target db name or location you can do it in one place rather than having to change it 33 times or more times.

  14. #14

    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
    @Goshx - I am not sure why you decided to PM me for assistance!

    You have two highly invested people assisting you already - and they are asking questions and making suggestions but seems you aren't "in tune" with what they are saying.

    Are you comfortable using DEBUG and stepping through code - examining your variables and what not?

    Have you ever used DEBUG.PRINT to write execution trace details to the debug window to assist you in seeing what's happening as your code runs?

    Not too many people are willing to download someones project and run it - we are all pretty much interested in seeing a code snippet that isn't working and helping you get that working.

    You have a lot of debugging and tracing to do yourself IMO...
    I've decided to ask you for help because this problem stays unsolved for more than a month.

    It is impossible to solve this without to see whole code. All of us like snippets but sometimes is impossible to find a bug without to see all code.

    I've spent a lot of time debugging and after that I decided to send my problem here. Therefore, I apologize myself to you again because I disturbed you.
    The rest of your advices are something very abstract. If all of us debug our programs until we find the solution, this forum wouldn't exist. Bad thing is that we can spent much of time for that.

  15. #15

    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 pointed out earlier one of your problems is here
    Code:
        SQL7 = "SELECT * FROM base_rec WHERE lvp_name='" & CStr(lblSel.Caption) & "';"
    
       
            If Trim(ListView1.ListItems(indx).SubItems(2)) = Trim(lblKliknutoNa.Caption) Then
                ListView1.ListItems.Remove (indx)
    You are deleting an item from the database based on one critera and then removing an item from the list view based on another. The item does not dissappear from the list because you must not be using the right value. It dissappears after the listview has been reloaded because it no longer exists in the database.
    DataMiser, thank you very much in any case
    !
    I'll try to concentrate myself on this part of code. The problem which you showed isn't a real problem. I simply translated some variables in English to make thing more simple. In the full project both variables are assigned to lblKliknutoNa.Caption value.

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

    Re: ListView problem: no refreshing after item deletion

    Quote Originally Posted by Goshx View Post
    ...I've spent a lot of time debugging and after that I decided to send my problem here...
    Does that mean you STEP through your code one line at a time and look at the variables in the IMMEDIATE window?

    Just want to make sure we don't have a language issue here.

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

  17. #17

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2012
    Posts
    616

    Re: ListView problem: no refreshing after item deletion

    OMG... sounds funny but when I changed for..next loop with this:

    vb Code:
    1. Do While Not rs33.EOF
    2.      rs33.MoveNext
    3. Loop

    errors related with the EOF disappeared!! I didn't know that Recordcount can make such kind of problems. )))

    The only problem which still remains is related with refreshing of deleted items in listview.
    As I told before.... if you click with mouse on some another treeview item and go back, deleted item doesn't more exist.

    Your suggestion about syntax in my code are good but I already know that. Various rsXX names for recordsets are made intentionally because of readability of code. When I finish with bugs, I'll clear the unnecessary things.

  18. #18

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2012
    Posts
    616

    Re: ListView problem: no refreshing after item deletion

    no....... they didn't disappear.... unfortunately. In the first moment it looked like that. In any case, this loop work better now.

  19. #19

    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
    Does that mean you STEP through your code one line at a time and look at the variables in the IMMEDIATE window?

    Just want to make sure we don't have a language issue here.
    Dear friend, I did that many times before I decided to ask for the help here. The program generates error with EOF and I can't catch why.....

  20. #20
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: ListView problem: no refreshing after item deletion

    In reference to the 1st issue. You need to post the actual code that you are using if you want us to see the problem. In the code you posted you are referencing 2 different things and that would be a problem.

    When you execute a remove from the list the object should be removed then and there. If it is still there after the statement has completed that indicates that you have did something wrong. Put a break point on that line where the remove takes place and see if the line executes. If it does not then that means no match was found. If it does get to this line check the value of your indx var and see if it is correct.

  21. #21

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2012
    Posts
    616

    Re: ListView problem: no refreshing after item deletion

    Here's the actual source code

    http://www.mediafire.com/?26zu52rnb12kgst

    It is impossible to understand the problem while you can't see how the program works.... I can send many posts here without any results

    You have to play a little bit with context menu in list view to realize whats' going on
    Last edited by Goshx; May 7th, 2012 at 05:09 PM.

  22. #22
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: ListView problem: no refreshing after item deletion

    I'm not really interested in downloading the project from mediafire. Simply post the real code for the second portion that is included in your first post. i.e. The routine where the delete and remove is actually done.

    Also you need to do as I suggested in my previous post and let us know the results.

  23. #23

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2012
    Posts
    616

    Re: ListView problem: no refreshing after item deletion

    vb Code:
    1. Option Explicit
    2.  
    3.  
    4. Dim con As ADODB.Connection
    5. Dim rs As ADODB.Recordset
    6. Dim rs2 As ADODB.Recordset
    7. Dim rs22 As ADODB.Recordset
    8.  
    9. Private sngListViewX As Single
    10. Private sngListViewY As Single
    11.  
    12. Dim nod As Node
    13. Dim lvwItem As ListItem
    14. Dim lvwItem2 As ListItem
    15.  
    16. '------------------------------------------------------------
    17.  
    18.  Private Const LVM_FIRST As Long = &H1000
    19.  Private Const LVM_HITTEST As Long = (LVM_FIRST + 18)
    20.  Private Const LVM_SUBITEMHITTEST As Long = (LVM_FIRST + 57)
    21.  Private Const LVHT_ONITEMICON As Long = &H2
    22.  Private Const LVHT_ONITEMLABEL As Long = &H4
    23.  Private Const LVHT_ONITEMSTATEICON As Long = &H8
    24.  
    25.  Private Const LVHT_ONITEM As Long = (LVHT_ONITEMICON Or _
    26.                                      LVHT_ONITEMLABEL Or _
    27.                                      LVHT_ONITEMSTATEICON)
    28.  Private Type POINTAPI
    29.    X As Long
    30.    Y As Long
    31.  End Type
    32.  
    33.  Private Type LVHITTESTINFO
    34.     pt As POINTAPI
    35.     flags As Long
    36.     iItem As Long
    37.     iSubItem  As Long
    38.  End Type
    39.  
    40.  Dim lX As Single, lY As Single
    41.  
    42.  Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    43.  
    44. '--------------------------------------------------------------------
    45.  
    46.  
    47.  
    48. Private Sub listView1_MouseUp(Button As Integer, Shift As _
    49.     Integer, X As Single, Y As Single)
    50.  
    51.             Dim HTI As LVHITTESTINFO
    52.     With HTI    '============================
    53.         .pt.X = (lX \ Screen.TwipsPerPixelX)
    54.         .pt.Y = (lY \ Screen.TwipsPerPixelY)
    55.         .flags = LVHT_ONITEM
    56.     End With
    57.    
    58.     Call SendMessage(ListView1.hwnd, LVM_SUBITEMHITTEST, 0, HTI)
    59.  
    60.  Dim lst As ListItem
    61.     If (HTI.iItem > -1) Then
    62.         Set lst = ListView1.ListItems(HTI.iItem + 1)
    63.  
    64.  
    65.     lblKliknutoNa.Caption = frmViewer.ListView1.ListItems(HTI.iItem + 1).SubItems(2)
    66.     lblKliknutoNa2.Caption = "item " & HTI.iItem + 1 & " i SubItem " & HTI.iSubItem
    67.    
    68.     End If
    69.     ' =================
    70.     sngListViewX = X
    71.     sngListViewY = Y
    72.  
    73.     If ListView1.ListItems.Count > 0 Then
    74.   If Button = vbRightButton Then
    75.     If Not (ListView1.SelectedItem Is Nothing) Then
    76.       If Not (ListView1.HitTest(X, Y) Is Nothing) Then
    77.         ListView1_Click
    78.         PopupMenu popMNU2
    79.       Else
    80.       End If
    81.     End If
    82.     popMNU2.Enabled = False
    83.   End If
    84.  End If
    85.    
    86.    
    87. End Sub
    88.  
    89.  
    90.  
    91. Private Sub cmdDodajNovu_Click()
    92.     frmDodaj_u_stablo.Show vbModal
    93. End Sub
    94.  
    95. Private Sub Form_Load()  '=======================
    96.  
    97.     Dim SQL As String
    98.     SQL = "SELECT DISTINCT kategorija FROM kategorije"
    99. Set con = New ADODB.Connection
    100.     con.CursorLocation = adUseClient
    101.     con.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\normativi.mdb"
    102. Set rs = New ADODB.Recordset
    103.     rs.Open SQL, con, 3, adLockOptimistic
    104. Call FormirajStablo
    105.  
    106. ListView2.Visible = False
    107.  
    108. cmdDodajNovu.Top = frmViewer.Height - 1600
    109. cmdUDaljiKat.Top = frmViewer.Height - 1600
    110. TreeView1.Height = frmViewer.Height - 2100
    111. End Sub
    112. '===========================================================
    113.  
    114. Private Sub FormirajStablo()    '======================= create TreeView1 tree
    115.  
    116. Dim i As Integer
    117. Set nod = TreeView1.Nodes.Add(, , "Recepti", "Baza receptura")
    118.  
    119. rs.MoveFirst
    120. For i = 0 To rs.RecordCount - 1
    121.     With TreeView1.Nodes
    122.         'rezultat stavljamo u treeview
    123.         Set nod = .Add("Recepti", 4, rs.Fields("kategorija"), rs.Fields("kategorija"))
    124.     End With
    125. rs.MoveNext
    126. Next i
    127. rs.Close
    128. Call UcitajStablo
    129. Set nod = Nothing
    130. End Sub
    131.  
    132. '===========================================================
    133.  
    134. Private Sub UcitajStablo()  '======================= load data into TreeView1
    135. Dim SQL As String
    136. SQL = "SELECT * From kategorije"
    137. rs.Open SQL, con, 3, 4
    138. Dim i As Integer
    139.  
    140. Dim nodtekst, a, bazni As String
    141. rs.MoveFirst
    142. For i = 0 To rs.RecordCount - 1
    143.     With TreeView1.Nodes
    144.         bazni = rs.Fields!kategorija
    145.         nodtekst = rs.Fields!podkategorija
    146.             Set nod = .Add(bazni, 4, nodtekst & " " & a & rs.Fields!Id, nodtekst & " " & a)
    147.     End With
    148. rs.MoveNext
    149. Next i
    150. rs.Close
    151. Set nod = Nothing
    152. End Sub
    153.  
    154. '===========================================================
    155.  
    156. Private Sub MenuQuit_Click()
    157. Unload Me
    158. End Sub
    159.  
    160. Private Sub TreeView1_Click()   '=======================
    161. With ListView1.ListItems
    162.     .Clear
    163. End With
    164.  
    165. If TreeView1.SelectedItem.Text = "Baza receptura" Then
    166. Exit Sub
    167.     ElseIf TreeView1.SelectedItem.Parent.Text = "Baza receptura" Then
    168.     Exit Sub
    169. Else
    170.     FormirajListView
    171. End If
    172.  
    173.  
    174. End Sub
    175.  
    176. '===========================================================
    177. '===========================================================
    178.  
    179. Public Sub FormirajListView()   '======================= Create ListView1
    180.  
    181.     Dim i   As Integer
    182.     Dim SQL As String
    183.     ListView1.ListItems.Clear
    184.     SQL = "SELECT * FROM baza_receptura WHERE pod_kategorija = " & "'" & TreeView1.SelectedItem.Text & "'" & " AND za_zivotinju = " & "'" & TreeView1.SelectedItem.Parent.Text & "' ORDER BY pod_kategorija DESC;"
    185.  
    186.     rs.Open SQL, con, 3, 4
    187.  
    188.     If rs.RecordCount = "0" Then
    189.         'MsgBox "Recepture doesn't exist fot this category"
    190.         Beep
    191.         rs.Close
    192.         Exit Sub
    193.     Else
    194.  
    195.         Do While Not rs.EOF
    196.             Set lvwItem = ListView1.ListItems.Add(1, , rs.Fields!za_zivotinju)
    197.             lvwItem.SubItems(1) = rs.Fields!pod_kategorija
    198.             lvwItem.SubItems(2) = rs.Fields!nazvanje
    199.             lvwItem.SubItems(3) = rs.Fields!komentar
    200.             lvwItem.SubItems(4) = rs.Fields!datum
    201.             rs.MoveNext
    202.         Loop
    203.  
    204.     End If
    205.     rs.Close
    206. End Sub
    207.  
    208. '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    209. Private Sub ListView1_Click()   '=======================
    210.    
    211.     ListView2.ListItems.Clear
    212.    
    213.     Dim lListItem   As ListItem
    214.     Dim string2klik As String
    215.  
    216.     Set lListItem = ListView1.HitTest(sngListViewX, sngListViewY)
    217.  
    218.     If (lListItem Is Nothing) Then
    219.         Exit Sub 'MsgBox "Niste nista izabrali"
    220.     Else
    221.         string2klik = lListItem.SubItems(2)
    222.         frmViewer.lblPrenos = string2klik
    223.  
    224.         Set rs2 = New ADODB.Recordset
    225.         Dim sql2 As String
    226.  
    227.         sql2 = "SELECT * FROM baza_receptura  WHERE nazvanje = " & Chr$(34) & string2klik & Chr$(34)
    228.         rs2.Open sql2, con, adOpenDynamic, adLockOptimistic
    229.         'rs2.MoveFirst '
    230.         txtNazvanje.Visible = True
    231.         txtNaziv.Text = rs2.Fields(4).Value '>>>DEBUGGER SHOWS EOF ERROR HERE!<<<
    232.         txtNaziv.Visible = True
    233.         txtKomentar.Text = rs2.Fields(5).Value
    234.         txtKomentar.Visible = True
    235.         txtRezultat.Text = ""
    236.  
    237.         Dim X           As Integer
    238.         Dim lvindeks As Integer
    239.         lvindeks = 1
    240.         For X = 8 To rs2.Fields.Count - 1
    241.         'popunjavanje male lv kontrole
    242.             If rs2.Fields(X).Value > 0 Then
    243.  
    244.                 'Set lvwItem = ListView2.ListItems.Add(1, , rs2.Fields(3))
    245.                 Set lvwItem2 = ListView2.ListItems.Add(lvindeks)
    246.                 lvwItem2.SubItems(1) = rs2.Fields(X).Name
    247.                 lvwItem2.SubItems(2) = CStr(rs2.Fields(X).Value)
    248.                 'lvwItem2.SubItems(3) = CStr(lvindeks)
    249.             lvindeks = lvindeks + 1
    250.             Else
    251.             End If
    252.         Next X
    253.         ListView2.Visible = True
    254.  
    255.         rs2.Close
    256.  
    257.     End If
    258.     Set lListItem = Nothing
    259.    
    260.  
    261. End Sub
    262.  
    263.  
    264. Private Sub ListView1_DblClick()    '=======================
    265.  
    266. Call ListView1_Click
    267.  
    268.     Dim lListItem   As ListItem
    269.     Dim string2klik As String
    270.  
    271.     Set lListItem = ListView1.HitTest(sngListViewX, sngListViewY)
    272.  
    273.  
    274.         string2klik = lListItem.SubItems(2)
    275.         frmViewer.lblPrenos = string2klik
    276.  
    277.         Set rs22 = New ADODB.Recordset
    278.         Dim sql2 As String
    279.  
    280.         sql2 = "SELECT * FROM baza_receptura  WHERE nazvanje = " & Chr$(34) & string2klik & Chr$(34)
    281.         rs22.Open sql2, con, adOpenDynamic, adLockOptimistic
    282.        
    283.         txtNazvanje.Visible = True
    284.         txtNaziv.Text = rs22.Fields(4).Value
    285.         txtNaziv.Visible = True
    286.         txtKomentar.Text = rs22.Fields(5).Value
    287.         txtKomentar.Visible = True
    288.         txtRezultat.Text = ""
    289.  
    290.         Dim X           As Integer
    291.         Dim stringic    As String
    292.         Dim naziv_polja As String
    293.         Dim razmak      As String
    294.         razmak = Chr$(9) & Chr$(9) & Chr$(9)
    295.  
    296.         For X = 8 To rs22.Fields.Count - 1
    297.            
    298.             If rs22.Fields(X).Value > 0 Then
    299.  
    300.                 stringic = txtRezultat.Text
    301.                 txtRezultat.Text = stringic & rs22.Fields(X).Name & razmak & rs22.Fields(X).Value & vbCrLf
    302.              
    303.             Else
    304.             End If
    305.  
    306.         Next X
    307.  
    308.         txtRezultat.Visible = True
    309.         frmDvaKlika.Show vbModal
    310.         rs22.Close
    311.  
    312. End Sub
    313.  
    314. '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    315.  
    316.  
    317. Private Sub TreeView1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    318.  On Error Resume Next
    319.  If Button = 2 Then
    320.   Dim hItem As Long, nod As Node, xRect As RECT, xPop As Integer, yPop As Integer
    321.   Set nod = TreeView1.HitTest(X, Y)
    322.   hItem = GetTVItemFromNode(TreeView1.hwnd, nod)
    323.   If hItem Then
    324.    TreeView_GetItemRect TreeView1.hwnd, hItem, xRect, CTrue
    325.  
    326.    xPop = TreeView1.Left + ScaleX(xRect.Left, vbPixels, vbTwips)
    327.    yPop = TreeView1.Top + ScaleY(xRect.Bottom, vbPixels, vbTwips)
    328.    PopupMenu popMNU, , xPop, yPop
    329.   End If
    330.  End If
    331. End Sub
    332.  
    333.  
    334.  Private Sub ListView1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    335.     lX = X
    336.     lY = Y
    337.  End Sub
    338.  
    339. Private Sub mnulvPreimenuj_click()
    340.     frmNovoIme.Show
    341. End Sub
    342.  
    343. Private Sub mnulvKopiraj_click()  '<============== COPY LV ITEM
    344.  
    345.     Dim con          As ADODB.Connection
    346.     Dim rs6          As ADODB.Recordset
    347.     Dim rs6pom       As ADODB.Recordset
    348.  
    349.     Dim i            As Integer
    350.  
    351.  
    352.     Dim SQL6 As String
    353.     SQL6 = "SELECT * FROM baza_receptura WHERE nazvanje ='" & CStr(lblKliknutoNa.Caption) & "';"
    354.     Set con = New ADODB.Connection
    355.     con.CursorLocation = adUseClient
    356.     con.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\normativi.mdb"
    357.     Set rs6 = New ADODB.Recordset
    358.     rs6.Open SQL6, con, adOpenDynamic, adLockOptimistic
    359.        
    360.            
    361.     Set rs6pom = rs6.Clone
    362.     rs6pom.AddNew
    363.            
    364.     For i = 1 To rs6.Fields.Count - 1
    365.         rs6pom(i) = rs6(i)
    366.     Next i
    367.            
    368.     Dim lenstr As Integer
    369.     lenstr = Len(rs6.Fields(4).Value)
    370.    
    371.     Dim kopi_tekst As String
    372.     'kopi_tekst = rs6.Fields(4).Value
    373.     If InStr(lenstr - 9, rs6.Fields(4).Value, " (copy)", vbTextCompare) = 0 Then
    374.     rs6pom.Fields(4).Value = rs6.Fields(4).Value & " (copy)"
    375.  
    376.     rs6pom.Update
    377.     rs6pom.Close
    378.    
    379.     Else
    380.     MsgBox "ONLY ONE INSTANCE ALLOWED"
    381.     End If
    382.  
    383.     rs6.Resync
    384.     rs6.Close
    385.  
    386.     Call frmDvaKlika.apdejtujGlavniLV
    387.    
    388. End Sub
    389.  
    390. Private Sub mnulvUdaljiti_click() '<============== DELETE LV ITEM
    391.  
    392.     Dim con         As ADODB.Connection
    393.     Dim rs7         As ADODB.Recordset
    394.  
    395.  
    396.     Dim SQL7 As String '??
    397.     SQL7 = "SELECT * FROM baza_receptura WHERE nazvanje ='" & CStr(lblKliknutoNa.Caption) & "';"
    398.     'SQL7 = "DELETE FROM baza_receptura WHERE nazvanje ='" & CStr(lblKliknutoNa.Caption) & "';"
    399.     Set con = New ADODB.Connection
    400.     con.CursorLocation = adUseClient
    401.     con.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\normativi.mdb"
    402.     Set rs7 = New ADODB.Recordset
    403.     rs7.Open SQL7, con, adOpenDynamic, adLockOptimistic
    404.            
    405.     rs7.Delete
    406.    
    407.     rs7.Resync
    408.     rs7.Close
    409.  
    410.     Dim indx As Integer
    411.     Dim lvredova As Integer
    412.  
    413.     lvredova = ListView1.ListItems.Count
    414.     'For indx = ListView1.ListItems.Count To 1 Step -1
    415.     For indx = 1 To lvredova
    416.         If indx > lvredova Then Exit For
    417.                                             '
    418.         If Trim(ListView1.ListItems(indx).SubItems(2)) = Trim(lblKliknutoNa.Caption) Then
    419.             ListView1.ListItems.Remove (indx)
    420.             indx = indx - 1
    421.             lvredova = lvredova - 1
    422.         End If
    423.    Next
    424.  
    425.  
    426. Call frmDvaKlika.apdejtujGlavniLV
    427.  
    428. End Sub
    Last edited by Goshx; Mar 3rd, 2012 at 10:10 AM.

  24. #24

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2012
    Posts
    616

    Re: ListView problem: no refreshing after item deletion

    vb Code:
    1. Public Sub apdejtujGlavniLV()
    2.  
    3.     Dim con33 As ADODB.Connection
    4.     Dim rs33  As ADODB.Recordset
    5.  
    6.     Set con33 = New ADODB.Connection
    7.     con33.CursorLocation = adUseClient
    8.     con33.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\normativi.mdb"
    9.     Set rs33 = New ADODB.Recordset
    10.  
    11.     frmViewer.ListView1.ListItems.Clear ''==============
    12.    
    13.     Dim SQL33 As String
    14.     SQL33 = "SELECT * FROM baza_receptura WHERE pod_kategorija = " & "'" & frmViewer.TreeView1.SelectedItem.Text & "'" & " AND za_zivotinju = " & "'" & frmViewer.TreeView1.SelectedItem.Parent.Text & "' ORDER BY pod_kategorija DESC;"
    15.     rs33.Open SQL33, con33, 3, 4
    16.  
    17.    
    18.     Do While Not rs33.EOF
    19.         Set lvwItem = frmViewer.ListView1.ListItems.Add(1, , rs33.Fields!za_zivotinju)
    20.         lvwItem.SubItems(1) = rs33.Fields!pod_kategorija
    21.         lvwItem.SubItems(2) = rs33.Fields!nazvanje
    22.         lvwItem.SubItems(3) = rs33.Fields!komentar
    23.         lvwItem.SubItems(4) = rs33.Fields!datum
    24.         rs33.MoveNext
    25.     Loop
    26.  
    27.     'rs33.Resync
    28.     rs33.Close
    29.     con33.Close
    30.     Set rs33 = Nothing
    31.     Set con33 = Nothing
    32.    
    33.     frmViewer.ListView1.Refresh
    34.    
    35. End Sub

  25. #25

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2012
    Posts
    616

    Re: ListView problem: no refreshing after item deletion

    That's the main logic of this module. There's a lot of code for context menu handling but the rest is devoted to TreeView and ListView control.
    Last edited by Goshx; Mar 3rd, 2012 at 07:01 AM.

  26. #26
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: ListView problem: no refreshing after item deletion

    So did you set the breakpoint like I said before? If so what happened? If not then you should do so and let us know the results.

    I am curious why in the code above in one case you are using CSTR() and then in the other using TRIM() There is no point whatsoever in using CSTR() on a caption since caption is a string already even if it contains a numeric value. The trim on the other hand would be a problem if there are any leading or trailing spaces in the listview subitem you are testing.

    Also like I mentioned before there is no reason to use .resync

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

    Re: ListView problem: no refreshing after item deletion

    Line 188 in Post#23
    Code:
    If rs.RecordCount = "0" Then
    might give you problems as it will never = "0". (I think I'm surprised that you don't get a run-time error 13)
    It should be:
    Code:
    If rs.RecordCount = 0 Then

  28. #28

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2012
    Posts
    616

    Re: ListView problem: no refreshing after item deletion

    txtNaziv.Text = rs2.Fields(4).Value

    This line (231) generates error related with EOF

    Doogle
    There's a lot of crap code here, don't pay attention on that for now.

  29. #29
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,470

    Re: ListView problem: no refreshing after item deletion

    thread is too large for my wee brain this morning..

    (1) have you solved the listbox not showing the deletion straight away yet?
    if not have you tried simply refreshing the listbox directly after your command to delete the entry.

    like listbox.refresh or refresh listbox which ever works in your version

    (2) have you stuffed you code full of stops and/or msgboxes to access the condition of the data at all times during the process to track down the problem?

    here to help

  30. #30

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2012
    Posts
    616

    Re: ListView problem: no refreshing after item deletion

    Quote Originally Posted by incidentals View Post
    thread is too large for my wee brain this morning..

    (1) have you solved the listbox not showing the deletion straight away yet?
    if not have you tried simply refreshing the listbox directly after your command to delete the entry.

    like listbox.refresh or refresh listbox which ever works in your version

    (2) have you stuffed you code full of stops and/or msgboxes to access the condition of the data at all times during the process to track down the problem?

    here to help
    You didn't sleep well last night, I can see
    Not a listbox but listview.
    1) Yes. That line exists (33)
    2) Many things I already did without success. As the result of that you can see meny stupid commands which still exists in my code )))) Many desperate attempts to do something, that's it.
    Last edited by Goshx; Mar 3rd, 2012 at 09:07 AM.

  31. #31
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: ListView problem: no refreshing after item deletion

    In Posts 20, 22 amd 26. I have asked that you set a break point and see if the code executes a given line and if so check the value of your vars at that point then let us know what the result is. You have not even acknowledged this.

    This is something you need to do if you want to get your project working.

  32. #32

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2012
    Posts
    616

    Re: ListView problem: no refreshing after item deletion

    DataMiser
    Maybe you didn't see but in the post #28 i wrote that code in line 238 generates EOF error.
    Obviously, clicking on ListView, it checks database and try to fil txtNaziv.Text = rs2.Fields(4).Value but without success.

  33. #33
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: ListView problem: no refreshing after item deletion

    I saw it but that is not the issue I was addressing and not what I asked you to provide. I can not help if you ignore 1/2 of what I say.

    As for the EOF error this should never happen as you should be checking to make sure the record exists before you try to assign values from it.

  34. #34

    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 saw it but that is not the issue I was addressing and not what I asked you to provide. I can not help if you ignore 1/2 of what I say.

    As for the EOF error this should never happen as you should be checking to make sure the record exists before you try to assign values from it.
    I'm trying to be as much cooperative as I can. I appreciate your good will to help me but I can't understand what you wanted from me in posts #20 and #22.

    I've copied the whole source related with these problems. Also, I wrote where one of my problems is placed. The second problem with ListView refresh I can't locate at all. Even with the help of debugger.

  35. #35
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: ListView problem: no refreshing after item deletion

    Code:
        For indx = 1 To lvredova
            If indx > lvredova Then Exit For
                                                ' 
            If Trim(ListView1.ListItems(indx).SubItems(2)) = Trim(lblKliknutoNa.Caption) Then
                ListView1.ListItems.Remove (indx)
                indx = indx - 1
                lvredova = lvredova - 1
            End If
       Next
    You need to set a breakpoint on the line I have marked in red then run your program and try to remove an item from the list view. If it does not hit the break point then that is a problem. If it does hit the break point then check the value of your subitems(s) and your indx vars as see if they look correct for the item you are trying to delete.

    Let us know the result.

  36. #36
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: ListView problem: no refreshing after item deletion

    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

  37. #37

    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
    Code:
        For indx = 1 To lvredova
            If indx > lvredova Then Exit For
                                                ' 
            If Trim(ListView1.ListItems(indx).SubItems(2)) = Trim(lblKliknutoNa.Caption) Then
                ListView1.ListItems.Remove (indx)
                indx = indx - 1
                lvredova = lvredova - 1
            End If
       Next
    You need to set a breakpoint on the line I have marked in red then run your program and try to remove an item from the list view. If it does not hit the break point then that is a problem. If it does hit the break point then check the value of your subitems(s) and your indx vars as see if they look correct for the item you are trying to delete.

    Let us know the result.
    The breakpoint is triggered and listitem is removed correctly. It is some kind of mystery. During debugging everything is working fine ))))
    No errors shown.

  38. #38
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: ListView problem: no refreshing after item deletion

    What does this line do?
    Code:
    Call frmDvaKlika.apdejtujGlavniLV

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

    Re: ListView problem: no refreshing after item deletion

    Quote Originally Posted by Goshx View Post
    The breakpoint is triggered and listitem is removed correctly. It is some kind of mystery. During debugging everything is working fine ))))
    No errors shown.
    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.

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

  40. #40

    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
    What does this line do?
    Code:
    Call frmDvaKlika.apdejtujGlavniLV
    it calls subroutine for updating ListView1. I've sent the source code of it in the post #24

Page 1 of 2 12 LastLast

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