Refresh a listbox in container control

I’m having a problem refreshing the contents of a listbox in an embedded container control.

I have a cc with a listbox and a couple of buttons. The cc is embedded in a form (I’ll call it masterForm). Double clicking a listbox row opens a separate editing window that successfully saves the data.

I would like to refresh the cc’s listbox data without closing and re-opening the masterForm. I’ve tried adding a 'refreshListbox" method to the cc, adding one to the masterForm, etc, but no love.

Have done this many times before but never with a cc. Probably a Sunday afternoon brain cramp, but any help appreciated.


Thanks Roger, but that’s not working in my case (although it does if manually run from a button on either the container or the master form.

I’m trying to trigger this action when saving data in the separate window that I use to edit the listbox’s content. I have a method called RefreshListbox in the container that re-populates the listbox contents.i.e.

if dataSaved = true then winMasterForm.myContainerControl1.RefreshListbox end if

I tried putting the code above in the action event of a save button on the separate editing window, but it instantiates a new blank copy of the master form instead of refreshing the listbox contents.

This has me stumped today. I wonder if I need a handle to the actual window that contains the ‘calling’ listbox.

Misunderstood the problem. The Xojo Listbox is pretty good at displaying data, but not so good as a repository of data. The problem being what you have encountered here: the programmer often has need for that data elsewhere and accessing it from the LB can cause loss of encapsulation, inadvertant instantiation of windows, and other difficulties. Two possibly better approaches:

  1. As a “quick fix” for this situation, let the MasterScrn call the editing screen modally. When the editing screen is dismissed, it passes the changed values back to the MasterScrn which then updates the listbox (via a call to the CC). There are many examples floating around as to how to get data from a modal window from within a calling window.
  2. Better, create a custom class to hold the data. Now, each screen which needs access to that data can create an instance of the class and access all of the data without help from any other window. The listbox on the MasterScrn fills itself by accessing that custom class.
    You can also create a global instance of that class at the risk of less encapsulation.
    Hope this helps.

You’re tripping over implicit instantiation of the window. How do you open the window in the first place? Do you keep a global reference to it? If not, and if you only have a single instance of the window, you can search through the Window() list to find it and then call your method on that instance.

Better, pass a reference to your master window to the edit window and use that to trigger the listbox update.

[quote]Better, pass a reference to your master window to the edit window and use that to trigger the listbox update.

Thank you for both for your help. I was successful in passing a reference to the container control when instantiating the editing window in code, then calling a custom refresh method on the cc during the edit window closing routines.