Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

MFC combobox and listbox Control, Program shuts off when ENTER KEY is pressed

Posted on 2003-03-26
6
Medium Priority
?
1,390 Views
Last Modified: 2013-11-20
hello again,
1. how can I remove an item into a list box and combo box, assigning an index and getting the value of the selected item?

m_list1a.AddString("item1");
m_list1a.AddString("item2");
m_list1a.AddString("item3");

item1
item2
item3

supposedly if I selected item2 i want to display the index in editbox1, the value text in editbox2 and remove it Simultaneously?

2. In MFC why is that when I pressed the ENTER KEY
  (when the focused on the dialog box)
  the Entire Program Always SHUTS OFF how can I deal with that?
0
Comment
Question by:perci
3 Comments
 

Author Comment

by:perci
ID: 8216048
help guys
0
 

Accepted Solution

by:
FrenchFries earned 80 total points
ID: 8217493
1-  you need to get the index of item with LBN_SELCHANGE message for example (or double-click on the list box ):

int nIndex=m_listbox.GetCurSel();
int nCount = m_listbox.GetCount();
if ((nIndex != LB_ERR) && (nCount > 0))
{
if((MessageBox("Delete ?","Message",MB_YESNO)==MB_YES)
{
m_listbox.DeleteString(nIndex);
m_listboxResetContent();
....// init a again the listbox
}
}
The GetCurSel() method gives you the actual index.

2 Pressing on <ENTER KEY> is a basic mechanism provided with MFC that causes the dialog window closing.

Override OnOK ( ClassWizard if VC6 ) and you can let an empty method:

CMyDlg::OnOK()
{
// nutshell
}

It also worth for OnCancel()
0
 
LVL 1

Expert Comment

by:Mazen
ID: 8219076
Hi,
   To solve the enter key problem, you can also uncheck the "default button" check box in the OK and Cancel buttons' properties.
   Mazen
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

571 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