May 17th, 2006, 08:08 AM
#1
Thread Starter
Hyperactive Member
[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?
May 17th, 2006, 08:14 AM
#2
Fanatic Member
Re: Refresh/Repopulate Listview after Updating.
ideally form2 calling form1 sub ...not sure how to do that in .net though
May 17th, 2006, 08:20 AM
#3
Thread Starter
Hyperactive Member
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.
May 17th, 2006, 08:24 AM
#4
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
May 17th, 2006, 08:27 AM
#5
Thread Starter
Hyperactive Member
Re: Refresh/Repopulate Listview after Updating.
I forgot to add that, i wonder why Refresh function doesnt work!
May 17th, 2006, 08:29 AM
#6
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
May 17th, 2006, 08:30 AM
#7
Thread Starter
Hyperactive Member
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 .
May 17th, 2006, 08:36 AM
#8
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
May 17th, 2006, 08:39 AM
#9
Thread Starter
Hyperactive Member
Re: Refresh/Repopulate Listview after Updating.
VS 2005 pro. I will be gratefull
May 17th, 2006, 08:44 AM
#10
Fanatic Member
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
May 17th, 2006, 08:46 AM
#11
Re: Refresh/Repopulate Listview after Updating.
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
May 17th, 2006, 08:48 AM
#12
Fanatic Member
Re: Refresh/Repopulate Listview after Updating.
May 17th, 2006, 08:49 AM
#13
Re: Refresh/Repopulate Listview after Updating.
Its ok.. I am almost done with this sample, and then I will post the source code.
May 17th, 2006, 08:51 AM
#14
Fanatic Member
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
May 17th, 2006, 08:53 AM
#15
Thread Starter
Hyperactive Member
Re: Refresh/Repopulate Listview after Updating.
Ggalla1779, thanks for the link. The helper there, describes what i want but his logic never helped.
May 17th, 2006, 09:04 AM
#16
Re: Refresh/Repopulate Listview after Updating.
Attached Files
May 17th, 2006, 09:15 AM
#17
Thread Starter
Hyperactive Member
Re: Refresh/Repopulate Listview after Updating.
Thanks. Let me take a look.
May 17th, 2006, 09:45 AM
#18
Fanatic Member
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
May 17th, 2006, 09:47 AM
#19
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)
May 17th, 2006, 09:50 AM
#20
Thread Starter
Hyperactive Member
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!
May 17th, 2006, 09:50 AM
#21
Fanatic Member
Re: Refresh/Repopulate Listview after Updating.
ok ta.... I am looking at the vb code in good old notepad!!.... thanks for example!!
May 17th, 2006, 09:52 AM
#22
Re: Refresh/Repopulate Listview after Updating.
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.
May 17th, 2006, 09:59 AM
#23
Thread Starter
Hyperactive Member
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.
May 17th, 2006, 10:06 AM
#24
Fanatic Member
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
May 17th, 2006, 10:10 AM
#25
Re: Refresh/Repopulate Listview after Updating.
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...
May 17th, 2006, 10:10 AM
#26
Thread Starter
Hyperactive Member
Re: Refresh/Repopulate Listview after Updating.
Whats the message in the error?, is your insert/update form called frmUpdate?
May 17th, 2006, 10:11 AM
#27
Re: Refresh/Repopulate Listview after Updating.
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
May 17th, 2006, 10:13 AM
#28
Thread Starter
Hyperactive Member
Re: Refresh/Repopulate Listview after Updating.
Right thats it Klienma. I will give that a go.
Thanks for the time you put into it.
May 17th, 2006, 10:13 AM
#29
Fanatic Member
Re: Refresh/Repopulate Listview after Updating.
many thanks Kleinma...its realy just that 1 line that was offending
May 17th, 2006, 10:15 AM
#30
Thread Starter
Hyperactive Member
Re: Refresh/Repopulate Listview after Updating.
Just out of curiosity, why do u opt for listviews from datagrids
May 17th, 2006, 10:24 AM
#31
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
May 17th, 2006, 10:25 AM
#32
Re: Refresh/Repopulate Listview after Updating.
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.
May 17th, 2006, 10:33 AM
#33
Fanatic Member
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!!!
May 17th, 2006, 10:46 AM
#34
Re: Refresh/Repopulate Listview after Updating.
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.
May 17th, 2006, 11:56 AM
#35
Fanatic Member
Re: [RESOLVED] Refresh/Repopulate Listview after Updating.
clever....thanks for your help today that was interesting cheers George
May 17th, 2006, 12:00 PM
#36
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.
May 17th, 2006, 12:01 PM
#37
Fanatic Member
Re: [RESOLVED] Refresh/Repopulate Listview after Updating.
Jun 14th, 2006, 07:40 AM
#38
Thread Starter
Hyperactive Member
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
Forum Rules
Click Here to Expand Forum to Full Width