|
-
January 13th, 2010, 07:49 AM
#1
autocomplete edit box
Hello
I would like to know how we can do an autocomplete box, which will call a callback function in order to add data in a drop down list (listBox) in a edit box.
For instance, i type the first letters of a word , a call to the database is done and data is retrieved and display to the user in a dropdown list.
Thanks in advance
Last edited by mumuri; January 13th, 2010 at 09:21 AM.
-
January 13th, 2010, 08:10 AM
#2
Re: autocomplete edit box
As always, break the problem into its pieces.
1) Identify when a user has typed a character
2) Retrieve the edit control data
3) Query the database
4) Clear the list box
5) Add data from the database to the list box
Which piece(s) do you need help with?
-
January 13th, 2010, 08:30 AM
#3
Re: autocomplete edit box
If you need a sample, look here.
Gort...Klaatu, Barada Nikto!
-
January 13th, 2010, 08:58 AM
#4
Re: autocomplete edit box
hello
my problem is i don't know how to display the menu in my listbox
i tried something like this, but the focus is lost in the edit box
Code:
void CAutocompleteDlg::OnChangeEdit1()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
CString test;
m_editBox.GetWindowText(test);
CMenu l_menu;
RECT rect;
m_editBox.GetWindowRect(&rect);
l_menu.CreatePopupMenu();
l_menu.AppendMenu(MF_STRING, 1, "Section");
l_menu.AppendMenu(MF_STRING, 1, "Secte");
l_menu.AppendMenu(MF_STRING, 1, "Septique");
m_editBox.SetFocus();
int l_curSel = l_menu.TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_NONOTIFY | TPM_RETURNCMD, rect.left, rect.bottom, this);
l_menu.DestroyMenu();
}
thank for your example Mike Harnad, i already know about it but that's not exactly what i wan't. My problem is to display a list of word without losting the focus in the edit box.
-
January 13th, 2010, 09:07 AM
#5
Re: autocomplete edit box
You didn't say anything about a menu. What are you trying to accomplish there?
-
January 13th, 2010, 09:21 AM
#6
Re: autocomplete edit box
i m trying to create dynamically a listBox, then add elements to it and display it above the edit control without losting the focus.
i did it with a menu because i don't know how to create a listbox dynamically 
if you have the good syntaxe to create this autocomplete box with a listbox, i m interested .
thanks
Last edited by mumuri; January 13th, 2010 at 09:23 AM.
-
January 13th, 2010, 09:28 AM
#7
Re: autocomplete edit box
 Originally Posted by mumuri
i m trying to create dynamically a listBox, then add elements to it and display it above the edit control without losting the focus.
i did it with a menu because i don't know how to create a listbox dynamically
if you have the good syntaxe to create this autocomplete box with a listbox, i m interested .
thanks
I broke down the steps for you. Take them one at a time. If you don't have a whole lot of data, you could just use a drop list combo box, load it all up at once, and it'll do the work for you.
-
January 13th, 2010, 09:44 AM
#8
Re: autocomplete edit box
 Originally Posted by mumuri
...i did it with a menu because i don't know how to create a listbox dynamically 
Well, according to MSDN it is quite easy (see CListBox Class ):
... To create it directly, construct the CListBox object, then call the Create member function to create the Windows list-box control and attach it to the CListBox object.
Victor Nijegorodov
-
January 13th, 2010, 10:43 AM
#9
Re: autocomplete edit box
ok i managed to do it thanks to your advices
Code:
CString test;
m_editBox.GetWindowText(test);
//CMenu l_menu;
CListBox * l_box = new CListBox();
RECT rect;
m_editBox.GetWindowRect(&rect);
ScreenToClient(&rect);
rect.top = rect.bottom;
rect.bottom += 100;
l_box->Create(WS_CHILD|WS_VISIBLE|LBS_STANDARD|WS_HSCROLL, rect ,this,ID_LISTBOX);
l_box->AddString("choice 1");
l_box->AddString("choice 2");
l_box->AddString("choice 3");
l_box->AddString("choice 4");
l_box->AddString("choice 5");
l_box->AddString("choice 6");
now how can i add an event in my listbox to retrieve the content of the listBox ?
Last edited by mumuri; January 13th, 2010 at 11:02 AM.
-
January 13th, 2010, 11:13 AM
#10
Re: autocomplete edit box
Handle LBN_SELCHANGE notification.
Victor Nijegorodov
-
January 13th, 2010, 12:51 PM
#11
Re: autocomplete edit box
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|