Hi

I've reached a brickwall with wxHaskell's ListCtrl and I'm hoping for some 
help, 
please.

Conceptually what I want to do is create items in the ListCtrl and associate a 
unique identifier with each item. This identifier would not be displayed in the 
UI. An Int64 would be ideal but a String would be fine. When a user clicks on 
the item, I want to be able to retrieve this identifier and use it to find the 
associated data, in this case a database record.

The items are inserted into the ListCtrl ok with the following code:

showStudy :: ListCtrl l -> (Int,DicomStudy) -> IO ()
showStudy wgDbTable (idx,dcmStudy) = do
   listCtrlInsertItemWithData wgDbTable idx $ studyUid dcmStudy
   set wgDbTable [item idx := [(patientName . studyPatient) dcmStudy,
                               studyDescription dcmStudy,
                               studyDate dcmStudy]]

and the event handler looks like this:

onDbTableEvent :: HasturContext -> EventList -> IO ()
onDbTableEvent HasturCtx {guiDbTable=wgDbTable, guiSeriesList=wgSeriesList} 
event =
   case event of
     ListItemSelected idx -> do
       studyUid <- listCtrlGetItemData wgSeriesList idx
       infoM "Hastur" $ "DB Table event: " ++ show studyUid
       propagateEvent
     otherwise             ->
       propagateEvent

When the user clicks on the ListCtrl item I get an error dialog pop up saying:

"Couldn't retrieve information about list control item X"

where X is idx. The infoM call produces:

"DB Table event: 0"

What am I missing? I've tried listCtrl{Get/Set}Data, listCtrl{Get/Set}Text all 
with the same result. listCtrlDeleteItem in the event handler doesn't delete 
the 
item but produces the result: False.

I've tried searching for examples to no avail. I'm not using images for items 
at 
the moment as I was trying to keep it simple.

Is what I am trying to achieve possible or would I be better maintaining a 
Data.Map with a mapping between idx and the relevant data? If so, how would 
that 
affect things if the ListCtrl contents are re-ordered (e.g. sort by date)?

Sorry if this seems a stupid query, I'm new to Haskell and trying to learn 
after 
years of using imperative languages.

James

------------------------------------------------------------------------------
Nokia and AT&T present the 2010 Calling All Innovators-North America contest
Create new apps & games for the Nokia N8 for consumers in  U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store 
http://p.sf.net/sfu/nokia-dev2dev
_______________________________________________
wxhaskell-users mailing list
wxhaskell-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wxhaskell-users

Reply via email to