10-28-2009 04:18 PM
I have a multicolumn listbox in which dragging of objects to reorder them is enabled, and I have an event structure handling these drags as well as selection of different items in the list. A problem occurs because when dragging and dropping, LabVIEW generates a value change event before a drag event. In other words, if the user drags an item from position 7 to position 1, LabVIEW first generates a value change event with value 1, then generates a drag event indicating that item 7 has been dragged to position 1.
The reason this causes a problem is that the listbox is not the data, it's just a representation of the data for the user. The value of the listbox gives an index into an array of objects, and next to the listbox I have a subpane where I insert a VI that allows the user to edit the object; which VI is inserted here depends on the runtime type of the object.
To accomplish this, on a value change event, I take the new value to get an object from the array and call a method that gives a VI reference, which is then inserted into the subpane. On a drag event, I rearrange the array and then generate a value change event. So when the user rearranges the list with a drag operation, dragging an object of type A into position 1, previously occupied by an object of type B, the sequence of events is as follows:
1) Value change; new value = 1: Object at position 1 is type B, so VI B is inserted into the subpane.
2) Drag; old value = 7, new value = 1: Array is rearranged; object of type A is removed from position 7 and inserted at position 1.
3) Value change; new value = 1: Object at position 1 is type A, so VI A is inserted into the subpane.
The result of all this is that the controls for a type B object flash briefly before being replaced by the controls for a type A object. This is a minor but irritating interface glitch.
Is there a way to change this behavior? If that drag event weren't preceded by a value change, there would be no need to change the subpane at all on a drag event, since the same object is selected before and after; but in the value change event handler, I have no choice but to put a new VI in the subpane, since there seems to be no way of knowing whether the user selected a different item or dragged an item to a different spot.
10-29-2009 04:44 AM