Dynamic container control reference

[quote=252207:@Björn Dohle]another idea for your mouse exit:

http://documentation.xojo.com/index.php/ListBox.Selected

store the values of the listbox in an array property in main or the vdListBox Container Control after each selection in listbox. then this array lives on when vdSearch closes because of mouse exit. On mouse exit populate the main container control with the array of strings you have just selected.

this should work[/quote]
I`ll try this way and let you know how it works. thanks.

well it suppose to be so simple but yet so complicated the last idea sounds perfect but i don`t know the vdlistbox container control as it is as well dynamic, actually they are all named when i drop the control on the window, but how should i know which one is which that was my tricky part from the beginning :frowning:

I haven’t read all of this discussion, maybe I’m repeating, and I’m not clear on the processing you’re doing, but to send that signal, from the popup to the master list to the dictionary you just need to store a reference where to make the call.

What I’m going to present is not the best design but it’s the simplest. And I’m working off the first project posted.

When the vdSearch Popup gets MouseExit it want to send it’s data and Close. So vdSearch should have a reference where to send, which will be the vdListbox that showed it. Since vdListbox is showing the popover and knows itself it can set this reference. Then vdListbox needs a method to receive this data when it’s sent in MouseExit.

[code]//vdSearch
Property infoReceiver As vdListBox

//vdSearch
Sub MouseExit()

//collect selected rows
dim newItems() As String
for i As integer = 0 to lbSearch.ListCount - 1
if lbSearch.Selected(i) then newItems.Append( lbSearch.Cell(i,0) )
next

//send info to receiver
if infoReceiver <> nil then
infoReceiver.send(newItems)
end

self.Close //done

End Sub

//vdListBox.bbDropList.Action
Sub Action()

dim SearchPopup As New vdSearch //create Popover

SearchPopup.infoReceiver = Self //set where this Popover should send new data

//…

End Sub

//vdListBox
Sub send(newItems() As String)

//add the new info to lbData
for i As integer = 0 to newItems.Ubound
lbData.AddRow newItems(i)
next

//?? pass along data to dictionary ??

End Sub[/code]

Repeat this process to pass the info along to the dictionary/table, I’m not clear what you’re doing at this point. But basically vdListBox should have a reference to what it will call when it gets new info. Set this reference when the vdListbox is created or opened. I’m guessing that this reference will create a cyclic link which means the window won’t dispose of itself when closed. So you’ll want to nil this reference in vdListbox.Close to break the cycle.

There’s better designs but this should get you going I think.

[quote=252323:@Will Shank]I haven’t read all of this discussion, maybe I’m repeating, and I’m not clear on the processing you’re doing, but to send that signal, from the popup to the master list to the dictionary you just need to store a reference where to make the call.

What I’m going to present is not the best design but it’s the simplest. And I’m working off the first project posted.

When the vdSearch Popup gets MouseExit it want to send it’s data and Close. So vdSearch should have a reference where to send, which will be the vdListbox that showed it. Since vdListbox is showing the popover and knows itself it can set this reference. Then vdListbox needs a method to receive this data when it’s sent in MouseExit.

[code]//vdSearch
Property infoReceiver As vdListBox

//vdSearch
Sub MouseExit()

//collect selected rows
dim newItems() As String
for i As integer = 0 to lbSearch.ListCount - 1
if lbSearch.Selected(i) then newItems.Append( lbSearch.Cell(i,0) )
next

//send info to receiver
if infoReceiver <> nil then
infoReceiver.send(newItems)
end

self.Close //done

End Sub

//vdListBox.bbDropList.Action
Sub Action()

dim SearchPopup As New vdSearch //create Popover

SearchPopup.infoReceiver = Self //set where this Popover should send new data

//…

End Sub

//vdListBox
Sub send(newItems() As String)

//add the new info to lbData
for i As integer = 0 to newItems.Ubound
lbData.AddRow newItems(i)
next

//?? pass along data to dictionary ??

End Sub[/code]

Repeat this process to pass the info along to the dictionary/table, I’m not clear what you’re doing at this point. But basically vdListBox should have a reference to what it will call when it gets new info. Set this reference when the vdListbox is created or opened. I’m guessing that this reference will create a cyclic link which means the window won’t dispose of itself when closed. So you’ll want to nil this reference in vdListbox.Close to break the cycle.

There’s better designs but this should get you going I think.[/quote]

Hello Will, thanks for the update, it seems that my script is working it is deleting the dropbox items after a while to refresh space, i put this one here to be more permanent , project link, if you look into the project you will see that in the vdListBox -> bbDropDownList i`m defining SearchPopup as New vdSearch, so this thing creates an instance of vdSearch from my understanding and it uses it until “vdlistbox” dies as it is referenced inside vdlistbox. now if you see on wmain. that i have 4 new instances of vdlistbox as list1-list4, so what i get is vdsearch is dynamically referenced as it is a new instance as well vdlistbox as list1-listn now in order to create this 2 way communication between those 2 controls i guess that i have to do all the coding in the vdListBox and vdSearch controls so that when referenced it keeps the link, but this is what i cannot achieve , that is my big dilemma.

So far even this Drag& Drop works only one time because of course bad define on the Dictionary side. In order to cross reference them logically i defined the SearchDict into vdListbox , because it initiate it in GetRecord method it is on and active for the period of vdListbox , then in the bbDropList i referenced as SearchPopup.SearchDict(vdSearch contol) = self.SearchDict so it passes it to the vdSearch control as it is with the data, now it seems that i`m even here doing it wrong because it gets initiated in the method and then dissapears, so i guess i have to initiate it in the Open event maybe but on each Record refresh i have to destroy it as it becomes a new one with a new record.

Maybe i`m understanding wrong but it seems that it is to much messy now and confusing.

The idea like in the project is to be able to have like a helper (that popup) for the list to be populated. You just select the data, mouse exit and it gets dropped into vdListBox instance and as well into the dictionary in case they want to add something more, once they change the main record up then it starts all over again.
The idea of the Dictionary is to have the unicity of the record so no duplications in both lists.

Thanks again, i`ll start to study your code and see what i can wrap more.

I love those NilObjectException without any details , it seems that all are working ok with your changes until i change the main record and then it crashes with a NilObjectException on vdSearch.LoadList on lbSearch.DeleteAllRows line.

Maybe i should change that to the open event of the listbox instead of doing that on the button action.

Well it works, Thanks a lot to all of you, the issue was on the bbDropList button, i cancelled the Nil checking and now it`s ok .