CellClick and SelectionChanged

I have a listbox (actually a weblistbox) with a single row selection functionality.
However I want to have control over the users ability to change rows and change the current selection.
(When the user tries to change the selection I want to put up a dialog box and only if they answer yes to the dialog box do I want the dialog box selection to be changed.

Is there an event in the listbox I must handle and return true or false from in order to stop the SelectionChanged event from firing?
Any idea how to accomplish this?

MouseDown or CellClick will do it. Return True from either of them to cancel the selection.

I don’t see these events being able to return anything.
They are Subs…

Web or desktop?

I am not sure you can stop from firing, but you could handle with a window Boolean property, that you update when it fires.

[quote=19637:@Brian O’Brien](actually a weblistbox)
[/quote]
Makes a big difference, since the mouse click is handled on the client by the browser, whereas your Xojo code is being run on the server. You would have to inject some Javascript into the page in order to stop the mouse.

You could probably catch the WebListbox.SelectionChanged event
and then open your dialog. if the user pressed OK then you leave the selection, otherwise put it back to non selected using
WebListbox.Selected( row as Integer) As Boolean method.

http://documentation.xojo.com/index.php/WebListBox.SelectionChanged
http://documentation.xojo.com/index.php/WebListBox.Selected

I liked Derk suggestion and am trying it out.

It’s a bit odd because there is no ‘last index’ and I have to keep track of that myself.
I subclassed WebListBox and added a computed property called LastIndex.
Which is initially set to -1

[code]Sub SelectionChanged()
if me.ListIndex = -1 then // There is nothing selected
if me.LastIndex = -1 then // There has never been anything selected.
end if
else // something is now selected
if me.LastIndex = -1 then // This is the first time something has been selected.
me.LastIndex = me.ListIndex
else // there was a previous selection.
//put up a dialog box and ask if they want to change the selection.
dim d as new AbandonSelectionWebDialog
AddHandler d.CancelPressed, AddressOf DialogCancelPressed
AddHandler d.YesPressed, AddressOf DialogYesPressed
d.Show
end if
end if
End Sub

Sub DialogCancelPressed(d as AbandonSelectionWebDialog)
TheWebListBox.Selected(TheWebListBox.LastIndex) = true
End Sub

Sub DialogYesPressed(d as AbandonSelectionWebDialog)
TheWebListBox.LastIndex = TheWebListBox.ListIndex
End Sub[/code]

Do you think I should do all of the presentation of the the dialog box in the new subclass and define a new event called MySelectionChanged only when the user has confirmed that change? Must I change the name of the Event SelectionChanged?

Actually LastIndex can’t be used as a new property as it is already used by the class, so I used PreviousIndex.

However if the user decides not to allow the selection to change, then the method actually sets the list index back by

TheWebListBox.Selected(TheWebListBox.PreviousIndex) = true

Which results in two rows being selected, dispite the fact the mult select is false.
so!
TheWebListBox.Selected(TheWebListBox.ListIndex) = false
TheWebListBox.Selected(TheWebListBox.PreviousIndex) = true

Now only 1 line is selected… but guess what???

I get another SelectionChanged event.
So a further test to see if previous and current are the same and if they are well… then all is well.