Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [platform-swt-dev] Storing Objects in CCombo

Paul, I'm not an SWT expert but I believe you are limited to storing Strings
in the combo box items.

However, all SWT components support storing arbitrary data alongside the
widget so you can store the Object[] with the widget and retrieve the object
from that.

So it looks something like this:
   // Storage
   m_Combo.setItems(String[]) ;  // The strings the user sees
   m_Combo.setData("items", Object[]) ;  // The underlying objects.

   // Retrieval
   int index = m_Combo.getSelectionIndex() ;
   Object[] objects = m_Combo.getData("items") ;
   Object selected = objects[index] ;

It's not quite as simple as in Swing, but has the advantage that the choice
of what String to use per object is more flexible because you aren't limited
to Object.toString()'s output.

Doug

-----Original Message-----
Message: 1
Date: Fri, 17 Jun 2005 15:40:08 -0400
From: "Paul Cooper" <paul_premis@xxxxxxxxxxxxxxx>
Subject: [platform-swt-dev] Storing Objects in CCombo
To: "SWT Mailing List" <platform-swt-dev@xxxxxxxxxxx>
Message-ID: <20050617194155.8AC6F5D1@xxxxxxxxxxxxxxxx>
Content-Type: text/plain; charset="us-ascii"

Greetings list, I'm a SWT newbie but have worked with Swing for a
while.....I've done a fair amount of searching my question, and failed
miserably to find a solution to my question.
 
Is there a way to store Objects in the CCombo list? It appears from the API
that the only method available to set a combobox component list is
setData(String[]). Is there a method that allows storing Objects? Or is
there another Widget I should use for a Combo box?
 
TIA
 
Paul Cooper
Software Developer
EMS Performance Improvement Center
 
Department of Emergency Medicine
University of North Carolina-Chapel Hill
10002 Main Street
Chapel Hill, NC
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://eclipse.org/pipermail/platform-swt-dev/attachments/20050617/d7d28643/
attachment.html

------------------------------



Back to the top