Reusing a listbox for different purposes

I have an app with a listbox that essentially contains a list of files. I currently have it coded so when you double-click the file in the listbox, you are brought into an edit mode. Now I want to add functionality… call it “format mode” for the same list of files. I’d like to be able to reuse the same listbox, but how can I tell my program when top go to edit mode vs. format mode? To open and load the listbox, I am using a simple button from the main window., so I think I somehow need to keep track of which button I pressed to get the window to load and then I can put some logic to say “If I originally pushed ‘edit’” go into edit mode, else if I pushed ‘format’ go to format mode"

Thoughts on the best way to handle this so I can reuse the same window & listbox when selecting for these two different functions?

Simple way: Put a property in the window that your ListBox can check. When you open the window, you set that property, then the entire window will know whether it’s supposed to be Edit or Format.

myWnd.Show
myWnd.IsEdit = true // Or false for format

If I understand you right, the Listbox is in its own window that pops up and then is dismissed. The way I’d do it is by adding a method and a property to the window, something like this:

Sub ShowList(ListMode As Integer) Me.Mode = ListMode ' Mode is an integer property of the window ' code goes here to populate the listbox Me.Show ' display the window End Sub

Then, you can define any number of ‘modes’ that the you need to support. 0 might mean edit, 1 might mean format, 2 might mean something in the future, etc.

In your main window, you’d call it like this:

MyListWindow.ShowList(0) ' edit mode MyListWindow.ShowList(1) ' format mode

Another elegant method could be the use of rowtags or celltags in your listbox. For instance mark an clicked/edited row with the rowtag “EDIT”. So you can keep track of them in your “format mode”. Add an icon to all marked rows, change colors or fonts e.g. and unmark your row with empty rowtag when your file/item/object is saved or edit mode cancelled.

I do this. I have a single-window program where the main listbox is used in all four stages of the process it manages. In each stage some or all of the previous rows are used (but displayed differently) and new rows may get added or removed as needed. I keep track of the window state (since the listbox is ruled by the stage of the process the window is in) and I keep all listbox data in an array. Events in the listbox flag and change the array which in turn is reflected in the listbox.

I’m currently trying to move this functionality to DTListbox with variable degrees of success, but will keep the listbox behaviour for non-mac platforms.