Results 1 to 38 of 38

Thread: [RESOLVED] Refresh/Repopulate Listview after Updating.

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Resolved [RESOLVED] Refresh/Repopulate Listview after Updating.

    I have a listview(which shows users) on one form(call it form1). Its populated at form load by a sub located in form1.
    I then call up another form (call it form2) to update a user. After Updating, i call the sub in form one to refresh/repopulate the listview in form1.
    The listview fails to refresh. What should i do? do i need to raise an event or something else?

  2. #2
    Fanatic Member Ggalla1779's Avatar
    Join Date
    Feb 2006
    Location
    Glasgow
    Posts
    532

    Re: Refresh/Repopulate Listview after Updating.

    ideally form2 calling form1 sub ...not sure how to do that in .net though

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Re: Refresh/Repopulate Listview after Updating.

    Ggalla1779.If form1 is a public class, in form2, declare a variable as its class name, then call its methods using the variable.

  4. #4
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Refresh/Repopulate Listview after Updating.

    is each item in the listview to represent one user?

    sort of like you have a list of users, and when you double click a row, it opens form2 so you can edit that 1 user?

    If that is the case, you shouldn't repopulate the entire listview because 1 row is changed, just update the 1 row itself

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Re: Refresh/Repopulate Listview after Updating.

    I forgot to add that, i wonder why Refresh function doesnt work!

  6. #6
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Refresh/Repopulate Listview after Updating.

    Refresh only invalidates a control, which means it is repainted.. it has nothing to do with loading/unloading items from the listview.

    All controls have a refresh method

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Re: Refresh/Repopulate Listview after Updating.

    Thanks Kleinma,
    I click on one row, then click the update button to open another form. So when i update, i update one row. But the snag is showing the updates of that row in the listview just after updating from another form.

    *****EDITS****************
    When i click the update button, form1 remains visible for the user to see if his/her updates are going through.
    Last edited by maps; May 17th, 2006 at 08:36 AM.

  8. #8
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Refresh/Repopulate Listview after Updating.

    well since all the controls in the form2 are automatically exposed to form1 (because they are declared as "friend") you can get the values entered in the edit form and update the single row. I can show you a small example if you tell me which version of VS you use

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Re: Refresh/Repopulate Listview after Updating.

    VS 2005 pro. I will be gratefull

  10. #10
    Fanatic Member Ggalla1779's Avatar
    Join Date
    Feb 2006
    Location
    Glasgow
    Posts
    532

    Re: Refresh/Repopulate Listview after Updating.

    I use the listrow technique in Access, to open and edit records then when form2 closes. There is event to detect form1 is active again.

    So what Kleinma is saying is whn u close form2 u need to call form1s listviews refresh method

    I found this
    MainForm.updateNumbersList()
    at
    http://www.vbcity.com/forums/topic.asp?tid=78722&page=1

    Dont know if thats what u were looking for though

  11. #11
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Refresh/Repopulate Listview after Updating.

    Quote Originally Posted by Ggalla1779
    So what Kleinma is saying is whn u close form2 u need to call form1s listviews refresh method
    No what I was saying is that refresh has nothing at all to do with updating a listview

  12. #12
    Fanatic Member Ggalla1779's Avatar
    Join Date
    Feb 2006
    Location
    Glasgow
    Posts
    532

    Re: Refresh/Repopulate Listview after Updating.

    oops sorry K

  13. #13
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Refresh/Repopulate Listview after Updating.

    Its ok.. I am almost done with this sample, and then I will post the source code.

  14. #14
    Fanatic Member Ggalla1779's Avatar
    Join Date
    Feb 2006
    Location
    Glasgow
    Posts
    532

    Re: Refresh/Repopulate Listview after Updating.

    thats great...I mostly use Access databases and have only used .net 03 to display info. So I could use this in the classic List...edit... back to updated list.

    cheers

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Re: Refresh/Repopulate Listview after Updating.

    Ggalla1779, thanks for the link. The helper there, describes what i want but his logic never helped.

  16. #16
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Refresh/Repopulate Listview after Updating.

    Here you go.
    Attached Files Attached Files

  17. #17

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Re: Refresh/Repopulate Listview after Updating.

    Thanks. Let me take a look.

  18. #18
    Fanatic Member Ggalla1779's Avatar
    Join Date
    Feb 2006
    Location
    Glasgow
    Posts
    532

    Re: Refresh/Repopulate Listview after Updating.

    kleinma is it a 2005 sample.... my 2003 said written in newer version. I will have to wait till I get home

  19. #19
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Refresh/Repopulate Listview after Updating.

    Yes, its in VS 2005, as the thread starter (maps) said that is what he is using.

    (however there is nothing being done in the code itself that wouldn't work in 2003)

  20. #20

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Re: Refresh/Repopulate Listview after Updating.

    Great Kleinma. You are soooooooooooooooooooooooooooooooooooooooooo.
    god....err.......good.

    Thanks Man.
    So this can also be done for datagrids or datagridviews!

  21. #21
    Fanatic Member Ggalla1779's Avatar
    Join Date
    Feb 2006
    Location
    Glasgow
    Posts
    532

    Re: Refresh/Repopulate Listview after Updating.

    ok ta.... I am looking at the vb code in good old notepad!!.... thanks for example!!

  22. #22
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Refresh/Repopulate Listview after Updating.

    Quote Originally Posted by maps
    So this can also be done for datagrids or datagridviews!
    Yes I am sure it can, however I don't really use those controls ever. Most of my projects warrant the use of a listview over any sort of data bound grid control.

  23. #23

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Re: Refresh/Repopulate Listview after Updating.

    I also wonder, how would some one, declare the LVI if he wants to just insert Data.
    I am thinking that it would take the same routine.

    ****EDITS********
    In the case of a ListView not datagridview.

  24. #24
    Fanatic Member Ggalla1779's Avatar
    Join Date
    Feb 2006
    Location
    Glasgow
    Posts
    532

    Re: Refresh/Repopulate Listview after Updating.

    grr moved it to 2003 am getting error at 1 line "F = New frmUpdate"

    I know this is your question MAPS so excuse the my side point!!

    cheers George

  25. #25
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Refresh/Repopulate Listview after Updating.

    Quote Originally Posted by maps
    I also wonder, how would some one, declare the LVI if he wants to just insert Data.
    I am thinking that it would take the same routine.

    ****EDITS********
    In the case of a ListView not datagridview.
    In that cause you would simply add a new listviewitem to the listview, with the data, instead of updating an existing one...

  26. #26

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Re: Refresh/Repopulate Listview after Updating.

    Whats the message in the error?, is your insert/update form called frmUpdate?

  27. #27
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Refresh/Repopulate Listview after Updating.

    Quote Originally Posted by Ggalla1779
    grr moved it to 2003 am getting error at 1 line "F = New frmUpdate"

    I know this is your question MAPS so excuse the my side point!!

    cheers George
    I'll move the code to a 2003 project and post that as well

  28. #28

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Re: Refresh/Repopulate Listview after Updating.

    Right thats it Klienma. I will give that a go.
    Thanks for the time you put into it.

  29. #29
    Fanatic Member Ggalla1779's Avatar
    Join Date
    Feb 2006
    Location
    Glasgow
    Posts
    532

    Re: Refresh/Repopulate Listview after Updating.

    many thanks Kleinma...its realy just that 1 line that was offending

  30. #30

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Re: Refresh/Repopulate Listview after Updating.

    Just out of curiosity, why do u opt for listviews from datagrids

  31. #31
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Refresh/Repopulate Listview after Updating.

    Here you go. there is both a 2003 and 2005 version.


    I also added the ability to "Add New" instead of just update.
    Attached Files Attached Files

  32. #32
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Refresh/Repopulate Listview after Updating.

    Quote Originally Posted by maps
    Just out of curiosity, why do u opt for listviews from datagrids
    I feel they have more control, and I like to keep my data layer seperate from my GUI layer.

    Also since it is a standard windows control, users are generally very familiar with how the listview operates...

    its a little bit of preference too though.

  33. #33
    Fanatic Member Ggalla1779's Avatar
    Join Date
    Feb 2006
    Location
    Glasgow
    Posts
    532

    Re: Refresh/Repopulate Listview after Updating.

    Many thanks for the 2003 version, I hadnt passed LVI to update form...ho hum!!!

    I am a bit confused how the Update form closes with line

    Me.DialogResult = Windows.Forms.DialogResult.OK

    I get the byref bit and its cool and fast that the whole listview doesnt have to be updated...thats great!!!

  34. #34
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Refresh/Repopulate Listview after Updating.

    Quote Originally Posted by Ggalla1779

    Me.DialogResult = Windows.Forms.DialogResult.OK
    When you set the forms dialog result, it hides the form

    from MSDN
    The Close method is not automatically called when the user clicks the Close button of a dialog box or sets the value of the DialogResult property. Instead, the form is hidden and can be shown again without creating a new instance of the dialog box. Because of this behavior, you must call the Dispose method of the form when the form is no longer needed by your application.
    you will notice i dispose of the form in the Finally part of the try/catch block.

  35. #35
    Fanatic Member Ggalla1779's Avatar
    Join Date
    Feb 2006
    Location
    Glasgow
    Posts
    532

    Re: [RESOLVED] Refresh/Repopulate Listview after Updating.

    clever....thanks for your help today that was interesting cheers George

  36. #36
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [RESOLVED] Refresh/Repopulate Listview after Updating.

    Don't forget of course, that the examples provide no error handling or data validation, and you would no doubt want that in a real world application.

  37. #37
    Fanatic Member Ggalla1779's Avatar
    Join Date
    Feb 2006
    Location
    Glasgow
    Posts
    532

    Re: [RESOLVED] Refresh/Repopulate Listview after Updating.

    yup ....cheers

  38. #38

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Re: [RESOLVED] Refresh/Repopulate Listview after Updating.

    Back Again.
    I am using Edit(method2) in your last example. I would like to call up a message, if one tries to type in a name that duplicates the other Names in the Listbox.
    If One Leaves or types in the Orignal Name he is trying to Edit, then bingo...no message pops up.
    How can i achieve this?

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