Problem with a ListBox + SetItemData

Started by krunch, November 01, 2012, 05:42:19 PM

Previous topic - Next topic

krunch

Hi

I have a ListBox with wich I'd want to use ItemData, but SetItemData doesn't seem to record my list ..
Example :

Code (autolisp) Select
(defun c:Project_Form_OnInitialize ()
    (dcl_Control_SetList Project_Form_lst0 '("a" "b" "c")
    (dcl_Control_SetItemData Project_Form_lst0 '(0 1 2))

    (print (dcl_Control_GetItemData Project_Form_lst0))
)

> (0 0 0)

Did I miss something ?

owenwengerd

The code in your post is using the item data functions incorrectly and results in argument exceptions. If you don't see the exception message dialogs, use (dcl_SuppressMessages NIL) to turn them back on. Please take a look at the function syntax of (dcl_ListBox_SetItemData) and post back if you have additional questions.

krunch

Ok thanks Owen

I had looked at the 'ItemData' property in the help ..
QuoteSet Function   (dcl_Control_SetItemData Project_Form_lst0 NewValue [as List of Longs])
Does it means that we can't apply it to List Box (only combo boxes) ?

The error message is not triggered, even with (dcl_SuppressMessages NIL)

owenwengerd

Sorry, I misread your original code and didn't notice that you were setting the property vs. calling the SetItemData method. It is indeed a bug, and I have fixed it now for the next build. In the meantime, you can work around the bug by getting and setting individual data for items using the GetItemData and SetItemData methods.

krunch

Ok

Just another remark : when you drag and drop items from a listbox to another the ItemData doesn't seem to follow (?)

owenwengerd

The default drag/drop handler is very basic and only copies the item text to the clipboard as plain text. To include the item data, it would either need to be encoded into the item text, or the list control would need to use a custom clipboard format for storing both item text and item data together. Modifying the item text is problematic because the encoded item data would then get dropped into places where it wouldn't be expected. The custom clipboard format would probably work, but it's not easy to implement.

I'll agree that the current behavior is a bit unintuitive when dragging from listbox to listbox, but that in itself is probably not enough reason to invest the effort in implementing a new clipboard format plus the code to handle the new format during drag and drop operations. In any case, you can create a custom drag/drop handler that transfers the item data for your own listbox control, so with a little work you should be able to work around the problem locally.

krunch

ok, this structure is already enough to do many things and it's true that we can transfer the item data with dragndrop event .. Thanks