Re: CListBox question again
Hi Al,
I'm glad you got it to work. I thought of this (responded earlier, but just
noticed more posts in the thread so I went back to read them). I'm guessing
the sort property of the listbox is set to true. Make sure that is what you
want (sorting is handy sometimes, but sometimes you want the items in the
order you specified). Apologies, I should have thought of that before.
Anyway, I'm glad you having it working and now you've had a great tutorial
on listboxes. Now that you have it all figured out, switch it to a
CListCtrl with an editable column :o)
Another way to do what you're doing is to assign the index (from the array)
to the data item using SetItemData() using the index returned from
AddString(). That way you don't have to do all that pointer stuff since you
can just use it as an index to your "name" object array. When you call
GetItemData() for the index of an item in the listbox it will just return
the index into the array for that item. That might be less code and easier
to understand in the long run.
CName* pName;
for(int nArrayItem=0; nArrayItem < m_SomeArray.GetSize(); ++nArrayItem)
{
pName = (CName *)m_SomeArray.GetAt(nArrayItem);
if(pName != NULL) {
int nListIndex = c_ListNames.AddString(pName->m_Name);
c_ListNames.SetItemData(nListIndex, nArrayItem);
}
}
// Later that same code
int nListIndex = c_ListNames.GetCurSel();
CName *pName = (CName
*)m_SomeArray.GetAt(c_ListNames.GetDataItem(nListIndex));
Now you're not messing with pointers so much and you're always getting them
from one source (the object array).
Tom
"Al" <Al@discussions.microsoft.com> wrote in message
news:840F8D59-EBA1-42AA-849C-1223D672D967@microsoft.com...
This was it!!!!!!!! Thank you Thank you Joe. By using the return value
from
AddString fixed everything. YEEEE HAAAAA
And thanks to all of the posts, they help me tremendously.
--
Just Al