Capture Listbox item

I have a listbox created.  I want to capture the string that is enclosed in the listbox when a user double clicks on it.  I am fairly new to MFC so the more detailed explanation the better.  I have set up an event so when you doubleclick on the listbox it goes to a function called OnDoubleClick();  Any help would greatly be appreciated. Thanks!
Who is Participating?
GlennDeanConnect With a Mentor Commented:
   You can accomplish this by doing the following:
   In ClassWizard, click on the "Member Variables" tab and make sure "Class name" is your dialog.  Then, highlight your listbox (I should say highlight the resource ID of the list box).  Click "Add variable" and choose the default CString (give it a name like m_strListBoxText).  
  Now, in your OnDoubleClick handler, simply call UpdateData(TRUE) and you've captured the text to m_strListBoxText after the user double clicks on the item in your listbox.  
   Note that UpdateData(TRUE) simply transfers the info on the dialog to the associated data member (in your case the double-clicked entry text gets transferred to m_strListBoxText).
   The only problem I had with capturing the text is IF you have a handler for when the user single-clicks on an item and you have a double-click handler, then the single-click handler executes while the double-click doesn't.  SO, make sure you only have a double-click handler.
epastoorAuthor Commented:
Thank you so much! This worked to a charm! I appreciate all the detail you went into for me!  Thanks a bunch
All Courses

From novice to tech pro — start learning today.