codingForFun
codingForFun

Reputation: 123

Selected cells CGridCtrl from codeproject

I need to find selected cells for the control CGridCtrl using the following code.

CCellRange cells = m_Grid.GetSelectedCellRange();
if( cells.Count() == 0 )
    return ;
    for (int i = cells.GetMaxRow(); i >= cells.GetMinRow(); i--)
    {
        for (int j=cells.GetMinCol(); j<=cells.GetMaxCol();j++)
        {
            BOOL selected = m_Grid.GetCell(i,j)->IsSelected();
            TRACE(_T("Row %d Column %d Selected = %d State %d\n"),i,j,selected, m_Grid.GetCell(i,j)->GetState());
            if(selected)
            {
                            m_Grid.DeleteRow(i);
                break;
            }
        }
    }

Since the cells I selected are not contiguous, I need to use IsSelected() to find a cell selected. The only last cell return TRUE. Is there a way to determine the cells selected for the control?

Upvotes: 0

Views: 1654

Answers (1)

xMRi
xMRi

Reputation: 15365

I don't know if the flag in the cells are correct, but the correct function to check if a cell is selected are:

BOOL CGridCtrl::IsCellSelected(CCellID &cell) const
BOOL CGridCtrl::IsCellSelected(int nRow, int nCol) const

Just check the implementation. There is a m_SelectedCellMap that contains all selected ranges.

Upvotes: 3

Related Questions