I would like to have multiple selections in a listbox and then use a contextual menu to apply “something” to the selection… but when the conteual menu is built the selection in the listbox reverts to one item (the first). Is there any way to retain the multiple selection, repress the reset of the selection etc? It seems to reset immediately in the ConstructContextualMenu event, so I can’t grab the selection before appending to the base menu.
what is your constructcontextualmenu code ?
I am able to get the contextualmenu in a listbox with multiple selection
so your code must be the cause of the trouble
hey, it seems you’re right …
if you ctrl-clic the mouse the selection is retained
if you right-clic the selection is erased and only one line is selected …
seems it needs a bug report !
Faster probably not. The listbox is all custom code. AFAIK it’s not relying on any native controls to work.
I think what I would prefer would to have a less generic listbox and split it up into different, more specific, controls: Listbox, Hierarchical ListBox/Treeview, Grid (with containers).
We all spend way to much time customizing the ListBox and while it works I’m not sure anyone is especially happy with it. But then again I (and many others) have been wishing for a more powerful Listbox for a long time.
[code]Function MouseDown(x As Integer, y As Integer) As Boolean
Redim ListBox1Selected(-1)
for i as integer = 0 to listbox1.ListCount-1
ListBox1Selected.append(Listbox1.Selected(i))
next
End Function
[/code]
In ListBox1.ConstructContextualMenu
Function ConstructContextualMenu(base as MenuItem, x as Integer, y as Integer) As Boolean
for i as integer = 0 to ListBox1Selected.Ubound-1
Listbox1.selected(i) = ListBox1Selected(i)
next
Make it powerful and very complete, and it becomes a nigtmarish, very complex control. Think NSTableView which by the admission of anybody who tried to implement it in Xojo lost a few hairs in the process.
Make it simpler to use, a lots of people will be able to master it relatively easily, and if necessary, expand it with some efforts.
I think Xojo wisely picked the second idea. Why they did not chose to implement a simplified version of the native control probably has to do with the necessity to have the same control cross platform.
I am reasonably sure it satisfies a vast majority or beginners, who appreciate the low learning curve. Of course, as one gains in competence, barriers appear that soon become annoying.
NSTableView implementations such as dtPlugins and the new control from Rob Egal do exist. But as the later posted while he was developing, he gained some appreciation for Xojo’s engineers. Difficult to make simple with complex.
@Michel Bujardet [quote]Keep it simple.[/quote]
Although I think the bug meantime has been fixed, for me, still using 2016v1.1, your solution has proved excellent.
Thank you.
[quote=335635:@Carlo Rubini]@Michel Bujardet
Although I think the bug meantime has been fixed, for me, still using 2016v1.1, your solution has proved excellent.
Thank you.[/quote]
Yes. This behavior changed in 2017r1. Now, a contextual click will not change the selection.