Jared Updike
Jared Updike

Reputation: 7277

Is there a SetText message for the Win32 ListBox control?

This is easy in .NET (not my question) but I'm trying to figure out if it is possible to simply change the text of a string in a Win32 list box control given an index.

There is a GetText function that takes an item index but nothing to change the text of an existing item/string. My workaround will be to remove it and add it back in the box (which is also a weird prospect since there is no single command to add a string + item data -- these must be done carefully by inserting the string and then setting the item data on the index of the inserted string, which is tricky (not possible?) with sorting active).

Upvotes: 10

Views: 3269

Answers (3)

Peter
Peter

Reputation: 1275

Although this question is old, but I think this documentation presented by Microsoft will be able to answer anyone questions based on this one.

So according to Microsoft documentation which you can find here

Changes the text of a list-view item or subitem. You can use this macro or send the LVM_SETITEMTEXT message explicitly.

void ListView_SetItemText(
   hwndLV,
   i,
   iSubItem_,
   pszText_
);

And it also presents other macros for managing the list box. You can build a wrapper around this macros to simplify handling list view controls, etc.

Upvotes: -1

Lynn Crumbling
Lynn Crumbling

Reputation: 13357

At the risk of being off topic...

I tend to use the ListView control all of the time. You'll want it in report view to mimic a listbox, and, as a plus, it supports multiple columns.

Oh.. and it has a LVM_SETITEM Message :)
http://msdn.microsoft.com/en-us/library/bb761186(v=VS.85).aspx

Upvotes: 2

Anders
Anders

Reputation: 101616

Yes, the lack of a LB_SETITEMTEXT message is a bit weird.

You should put your Delete+Insert+SetData calls between calls to WM_SETREDRAW...

Upvotes: 8

Related Questions