How to cancel selection in ListView? - javafx

I try to cancel user selection in a ListView according a condition. I tried to consume mouse clicked and mouse pressed event in ListView and ListCell but it didn't work. I don't understand why bu events occur after the selected item property change.
How can I cancel the user selection?

If I understand correctly, you want to prevent users from selecting items by clicking on it. I further suppose that you tried a solution like this:
listView.addEventHandler(MOUSE_CLICKED, click -> click.consume());
That does not prevent other click handlers from being executed. Even if it did, the internal event handler seems to be fired before your event handler, since the selected item is changed before your handler is executed.
You need to add an event filter to prevent any event handlers from being fired:
listView.addEventFilter(MOUSE_CLICKED, click -> click.consume());

listView.getSelectionModel().clearSelection();

Related

click events of combobox in flex

I found that in flex, combobox has 3 events: open, close, change
combobox events example
Let's say I selected A in my combo box. Then I might do 2 things:
I open combobox and click A option again
I open combobox and close it by clicking somewhere else (without clicking A option)
There is no selection change in either of the case above. And they both have open and close involved. So if I want these 2 actions have different behaviors, I can't programmatically distinguish them....
Is it possible to have a click event on combobox or combobox options?? I am using a data provider for my combobox...
Thanks a lot!!!
The ComboBox events do have a click event defined, although it is inherited.
Unless the ComboBox has a click event listener and calls preventDefault() to prevent the event from bubbling, you should be able to listen for the click event on a ComboBox without any issues.

Detect if Flex AdvancedDataGrid itemClick is actually a drag

Is there any way to detect if AdvancedDataGrid itemClick event is actually caused by the user dragging? I'd like to take action on click, but ignore drag.
you should add drag handler, dispatch new click event for the same target and kill drag event or stop it.
or just use standard click event

autopackback dropdownlist only if changed using mouse

I would like to perform a postback when the droplistlist selected value changes, but only if it was changed via expanding the downdown and clicking an option, not is the user tabs to the control and uses the arrow keys. The reason for this is simple, keyboard accessibility.
Postbacks are triggered using __doPostBack('uniqueidofcontrol', 'commandname'); so when the list changes value (I believe in onchange event), it posts to the server. You would need to not set autopostback. What you would need to do is tap into the click event (if there is one) and then call __doPostBack(..) method upon that event.
HTH.

Help! dragDrop event not firing for my TextArea control

I'm working on a simple view in my app that allows a user to drag an item from a list control and drop it onto a textarea.
Seems the dragEnter event fires just fine, but the dragDrop event does not.
i forgot to add the textarea as a drop target during my drag enter handler. :P

Trigger UpdatePanel on mouse over (as tooltip)

I need to display additional information, like a tooltip, but it's a lot of info (about 500 - 600 characters) on the items in a RadioButtonList.
I now trigger the update on a PanelUpdate when the user selects an item in the RadioButtonList, using OnSelectedIndexChanged and AutoPostBack. What I would like to do, is trigger this on onMouseHover (ie. the user holds the mouse a second or two over the item) rather than mouse click but I cannot find a way to do this.
You could try setting an AsyncPostBackTrigger on the updatePanel to watch the value of a hidden field. Then in the javascript onMouseHover event, increment the hidden value. This would fire the AsyncPostBackTrigger, updating the UpdatePanel.

Resources