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?
Re: autocomplete edit box
If you need a sample, look here.
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.
Re: autocomplete edit box
You didn't say anything about a menu. What are you trying to accomplish there?
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
Re: autocomplete edit box
Quote:
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.
Re: autocomplete edit box
Quote:
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 ):
Quote:
... 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.
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 ?
Re: autocomplete edit box
Handle LBN_SELCHANGE notification.
Re: autocomplete edit box