Solved

Initializing A ComboBox

Posted on 2001-06-12
6
689 Views
Last Modified: 2013-11-20
Hi,

I would like to add a combobox to my interface that will initially highlight a selection and include a list of options in the accompanying drop-down-list.  

I want to use the drop-down-list combobox because it does not allow users to type any information into the edit control.  However, I want to feed the combobox a string to display to the user intially using SetWindowText.  My problem is that I can't get SetWindowText to work with the drop-down-list combobox only the drop-down combo box.  Any suggestions for how I can get around this.

Thanks!
0
Comment
Question by:cneaton
6 Comments
 
LVL 6

Expert Comment

by:MichaelS
ID: 6182207
how to set the last one (for example)

// Select the last item in the combo box.
int nCount = pmyComboBox->GetCount();
if (nCount > 0)
   pmyComboBox->SetCurSel(nCount-1);


0
 

Author Comment

by:cneaton
ID: 6182250
Hi and thanks for the reply.  I actually need to extract some information from a file to display to the user in the interface.  So, I'll need to get the data from the file and then put it into the edit control.  However, the drop-down-list combobox won't let me do it.  I guess I could get the data from the file and then match it up to the available selections in the list and then set the display that way.  I was just wondering if there was an easier way.

Thanks again!
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 6182380
u can change the style of the combobox on runtime from drop-down to frop-list
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 4

Expert Comment

by:aponcealbuerne
ID: 6182444
try with AddString
Hope helps
0
 
LVL 4

Accepted Solution

by:
sri_darr earned 200 total points
ID: 6183434
Get the data from the file (say csData), and then

if (m_pMyCombo->FindString(csData) == CB_ERR)
{
    m_pMyCombo->AddString(csData);
}
m_pMyCombo->SelectString(-1, csData);


// Is this what u want ???
0
 

Author Comment

by:cneaton
ID: 6183593
Thanks so much, sri_darr!  This worked out great!  

I just have one note to future users,  FindString uses more than one parameter:
FindString( int nStartAfter, LPCTSTR lpszString )

Thanks again to everyone who responded!!!
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Replacement selected text 2 61
Looking for a specific application/software 2 109
move a line in eclipse 3 100
lucky13 challenge 11 141
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question