Class method to refresh a listbox or recordset?

I have an instance of a listbox in a container(cc1) that presents a list database entries for selection . Selected items from cc1 are processed in another container instance (cc2). I would like to have cc1 immediately reflect modifications saved in cc2.

I currently populate cc1 in the main window by setting a computed property (cc1.records) and passing a recordset. Cc1 then loads the recordset into a dictionary and populates the listbox. This was shortsighted, because I now need to refresh the cc1 display based on the results of saving the data in cc2.

I would like to be able to create a method in the cc1 class definition where I could pass the name of the method that populates the cc1 listbox. The method name would vary depending on the contents of the SourceList. Open to any suggestions. I’ve been reading up on delegates, and observer patterns, but still can’t figure out a generic way to generate the recordset in a class.

A RecordSet should only be used to temporarily and locally iterate through the results of a Database query. Copy the records you need to a Dictionary or an array of Dictionaries. Keeping the RecordSet around may lock resources on your database server/engine.

Brad, the recordset is already being loaded into a dict. My issue is I need to refresh the recordset and then repopulate the dict. I would like to accommodate that generically in the class rather than the instance.

Right now I have a function (FindAllSiteUsersForList) that populates the instance recordset (which populates the dict, et al). But this function is different for each instance.

How can I pass a reference to a function that would populate this recordset. I thought delegates may be the answer, but I’ve never used them in RB before. Do you have any suggestions?

The RecordSet is a very opaque structure that wraps database plugin query results. You wouldn’t manually load one from Xojo code.

I’ll play with delegates, they seem to provide what I need in early testing. Thanks for your help.

Add a method to cc1 that cc2 can call to update just the current row. It’s ok to have 2 methods, one the populates the listbox and one that updates a single row from another data source (ie., CC2 or some data structure that CC2 loads). I don’t think delegates are necessary here.

Thanks Tim, I might give that a shot.

I was trying to keep the containercontrols as independent as I can. So instead of passing a recordset to the control, I’d like to pass a reference to the method that returns the recordset. That way it could just update itself when it observes a data_modified event.

I could hard code the query in each instance of the control, but that seems less versatile…