Board index » cppbuilder » Can't get list view item to be selected

Can't get list view item to be selected

This is a basic question I know but I can't seem to get a list view item to be selected...

I have a list of items.  After deleting an item, instead of the default action of no items being selected, I want to select the previous item.

[Code]:

iOldItemIndex = pListItem->Index;

lv->Items->Delete(iOldItemIndex);

if(lv->Items->Count != 0)
  lv->Selected = lv->Items->Item[iOldItemIndex-1];

[end code]

The result is still that no item is selected.  I also try setting the ListItem's Selected property to true, but that doesn't work either.

What am I missing?

Thanks

 

Re:Can't get list view item to be selected


    pListItem = lv->Selected;
    if (pListItem)
    {
      iOldItemIndex = pListItem->Index;
      lv->Items->Delete(iOldItemIndex );
      if ((lv->Items->Count > 0) &&  (iOldItemIndex > 0))
      {
        lv->Items[iOldItemIndex -1]->Selected = true;
      }
    }
--
Clairebear

http://www.corkyscave.com
http://www.faqs.org/faqs/usenet/emily-postnews/part1/

Quote
"Eugene" <jsm...@aol.com> wrote in message news:3ca931e6$1_1@dnews...

> This is a basic question I know but I can't seem to get a list view item
to be selected...

> I have a list of items.  After deleting an item, instead of the default

action of no items being selected, I want to select the previous item.
Quote

> [Code]:

> iOldItemIndex = pListItem->Index;

> lv->Items->Delete(iOldItemIndex);

> if(lv->Items->Count != 0)
>   lv->Selected = lv->Items->Item[iOldItemIndex-1];

> [end code]

> The result is still that no item is selected.  I also try setting the

ListItem's Selected property to true, but that doesn't work either.
Quote

> What am I missing?

> Thanks

Re:Can't get list view item to be selected


Quote
Eugene <jsm...@aol.com> wrote in message news:3ca931e6$1_1@dnews...

> This is a basic question I know but I can't seem to get a list view item
to be selected...

> I have a list of items.  After deleting an item, instead of the default

action of no items being selected, I want to select the previous item.
Quote

I would rather work with items straight instead of their indexes:

int nIndex = pListItem->Index;
TListItem *NewSelItem = lv->Items->Item[nIndex - 1];

lv->Items->Delete(nIndex);
if (NewSelItem)
  lv->Selected = NewSelItem;
else
  lv->Selected = lv->TopItem;

Alex

Other Threads