Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how can I add items (strings) to a list control? 1

Status
Not open for further replies.

Sedai

Programmer
Mar 4, 2001
158
US
how can I add items (strings) to a list control?
Using SetDlgItemText(ID,"xxx");
doesn't work.
any suggestions. i just need some direction, no need to write long code.
thanks. Avendeval


 
to add an item to a list control :

LVITEM lvi;

lvi.mask = LVIF_TEXT;
lvi.iItem = i;
lvi.iSubItem = 0;
lvi.pszText = (LPTSTR)(LPCTSTR)(buf);
listItem = my_list_variable.InsertItem(&lvi);

where my_list_variable is a variable of the CListCtr
 
i don't have time to try this now but if i do everything right and it works - THANK YOU!
Avendeval


 
actually, i'm not sure how to use ur code since I don't have my List control like that, i had it created in the MFC dialog boxl; i can refer to the List control by its id
ID_LIST and such as
GetDlgItem(ID_LIST);
but the above function returns CWnd*
and not a CListCtr type.

How can I insert the text if all I have is the ID (int) of the list control in my dialog box.
Thanks.
Avendeval


 
It is very simple :

CListCtr * temp_list = (CListCtr*)GetDlgItem(ID_LIST);
and now you have your variable (it is a pointer now)
so you will use :

temp_list->InsertItem(&lvi);

i forgot to tell you that buf is a char * which has the string you want to add.

 
thanks, it's funny i just tried the casting minuted before I saw your post :) im glad you confirm that what i did is right. Thanks. Avendeval


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top