Click to See Complete Forum and Search --> : Using a List Box
Theone2k
October 21st, 2004, 08:07 PM
Is there a way when using a list box to add straings from a edit box into the top of the list box rather then being added on the bottom
EG
enter text into edit box hit enter
the text is then placed at the top of the list box
enter more text into the edit box hit enter
the new text is at the top of the edit box the old line is the next line down?
Using Microsoft Visual C++ 6.0
TBONE917
October 21st, 2004, 09:53 PM
if you create a member variable for the ListBox or get control using GetDlgItem:
CListBox *pList = (CListBox *)GetDlgItem(IDC_LIST1); // IDC_LIST1 being your list
pList->InsertItem(0, string);
this will insert the data variable string into the first position of the list box
you can get this data by calling GetWindowText on the edit box
chi_luci
October 25th, 2004, 02:46 AM
you might use a CListCtrl instead and insert item via InsertItem(.. ) function at any location...
Theone2k
October 25th, 2004, 07:02 PM
hmm....this is usefull but im V new to this and what you have said has gone right over my head could you explain a little more simpley
kirants
October 25th, 2004, 07:30 PM
1. Make sure you remove the sort style for the listbox ( I guess it is LBS_SORT )
Else, no matter what you try, the listbox class will reorder things the way it feels fit.
2. SendMessage(hWndListBox, LB_INSERTSTRING, ..... )
Theone2k
October 25th, 2004, 07:47 PM
at the moment i have
SendDlgItemMessage(hwnd, LST_CHAT, LB_SETITEMDATA, (WPARAM)index, (LPARAM)1);
if i try
SendDlgItemMessage(hwnd, LST_CHAT, LB_INSERTSTRING, (WPARAM)index, (LPARAM)1);
my program crashes is this not what you ment?
kirants
October 25th, 2004, 07:50 PM
You need to send the pointer to the string as lParam. It is crashing because you are sending 1 !!
Theone2k
October 25th, 2004, 07:56 PM
Thx for all the Help i now have it working :D one prob down now :D
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.