Selecting and deselecting a range of rows


The list box control class has a selection function SelItemRange(). This function, though missing in the CListCtrl class, is easily implemented.
// SelItemRange - Selects/Deselect a range of items
// Returns              - The number of new items selected
// bSelect              - TRUE to select, FALSE to deselect
// nFirstItem           - index of first item to select
// nLastItem            - index of last item to select
int CMyListCtrl::SelItemRange(BOOL bSelect, int nFirstItem, int nLastItem)
{
        // make sure nFirstItem and nLastItem are valid
        if( nFirstItem >= GetItemCount() || nLastItem >= GetItemCount() )
                return 0;

        int nItemsSelected = 0;
        int nFlags = bSelect ? 0 : LVNI_SELECTED;
        int nItem = nFirstItem - 1;
        while( (nItem = GetNextItem( nItem, nFlags )) >=0
                        && nItem <= nLastItem )
        {
                nItemsSelected++;
                SetItemState(nItem, bSelect ? LVIS_SELECTED : 0, LVIS_SELECTED );
        }
        return nItemsSelected;
}



Comments

  • Selecting all items quickly

    Posted by Legacy on 05/13/1999 12:00am

    Originally posted by: Phil Hall

    This will select all items the quickest way possible:
    
    


    void CMyListCtrl::SelectAllItems()
    {
    LV_ITEM theItem;

    theItem.mask = LVIF_STATE;
    theItem.iItem = -1;
    theItem.iSubItem = 0;
    theItem.state = LVIS_SELECTED;
    theItem.stateMask = 2;

    this->SetItemState(-1, &theItem);

    return;
    }

    Reply
  • Selecting multiple rows in a List control

    Posted by Legacy on 02/05/1999 12:00am

    Originally posted by: Kammie Dill

    I have a list control with over 100,000 items in it. I would like for the user of the app to be able to select all the items at once. I have provided a button on the toolbar for this, but the only way I know how to select all of the items is by looping through all 100,000 and setting the "select" state. This takes a long time and the screen flashes until all are selected. Is there a better way to do this?

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • CentreCorp is a fully integrated and diversified property management and real estate service company, specializing in the "shopping center" segment, and is one of the premier retail service providers in North America. Company executives travel a great deal, carrying a number of traveling laptops with critical current business data, and no easy way to back up to the network outside the office. Read this case study to learn how CentreCorp implemented a suite of business continuity services that included …

Most Popular Programming Stories

More for Developers

RSS Feeds