Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

updating a list view control from another form

Status
Not open for further replies.

fenris

Programmer
May 20, 1999
824
CA
I am trying to update the contents of a listview control that lives on one form from another form. The first form has a public sub routine that I want to use to refresh the contents of the control. The sub works fine when it is executed from the form that contains the listview control. But when it is called from another form, it doesn't do anything. When I trace through the code, I find that as soon as the code tries to update a control on the form, it causes a form_load event to occur as if it is creating a new form.

How could this be done in an OO way?
Troy Williams B.Eng.
fenris@hotmail.com

 
If the form_load method is being called it's probably because you're activating the first form. ie do you have the 2 forms displayed at the same time or do you have only form2 displayed and then use form1.Show to show form 1?

If the latter that should happen because you're loading the form again.
If the first try to use the setfocus method on form1 before you run the sub, but if this is the case that sounds preety weird because that shouldn't happen at all. Other thing you could do is to place that sub on a module(as public) at least to check if that way the code will run as you want.
 

One solution would be to load form2 when you start your project. In the load event of form1 put:

form2.show
form2.hide

This will cause form2 to be loaded (and the load event for form2), but when your call your update sub in the future the load event will not happen again (unless you have a unload form2 somewhere.

Sunaj
 
daimaou, I have both forms displayed at the same time and it is acting wierd! I have looked back on other projects that I have done updating the lsv from another form and they work fine(I even went so far as to copy the code from them)!

I have tried:

'on the second form
dim frm as form
set frm = frmForm1
frm.refreshLSV 'I have also tried having this sub in a seperate module, but it did the same thing...
set frm = nothing

On the first form I also have a date and time picker control on the first form. I follow the code through from where it starts in the second form, and everything seems to work fine till it hits the part where it references the listview control directly.

I am going to try reference the listview control directly, later tonight ( when I get some time) by:

'on the second form
dim lsv as listview
set lsv = frmForm1.ListView1
refreshLSV lsv 'This sub is contained in a seperate module.


With all the examples that I looked through, and with all my previous programs, what I am doing should work? Could this be a bug? I am running vb 6 with service pack 5.

Thanks for the replies...

Troy Williams B.Eng.
fenris@hotmail.com

 
Hi fenris that sound a little bit weird, but try this:
Instead of making

dim frm as form
set frm = frmForm1

Use frmForm1 directly to refer to this form instead of setting frm and see if you still get the same error. Also have a better look at your RefreshLSV method to see if there isn't some bad reference there.
Let me know if you find out anything.
 
What I ended up doing on the first form was:

form2.setproperties 'set all the properties required by this form

form2.show

'-------------
By calling the form this way it seems to allow me to update the listview control from the second form. This is very odd, indeed
Troy Williams B.Eng.
fenris@hotmail.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top