Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Report Control
  New Posts New Posts RSS Feed - Moving rows
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Moving rows

 Post Reply Post Reply
Author
Message
rock View Drop Down
Groupie
Groupie


Joined: 27 October 2005
Status: Offline
Points: 19
Post Options Post Options   Thanks (0) Thanks(0)   Quote rock Quote  Post ReplyReply Direct Link To This Post Topic: Moving rows
    Posted: 07 July 2006 at 4:58pm
I have a dialog box that contains a Report Control and a CSpinButtonCtrl.  I use the spin control to successfully move rows up or down within the Report control.  However, when I exit the dialog box I get an assertion error in the CXTPReportRows destructor during the call to CXTPReportRows::Clear().  Specifically to the line pRow->InternalRelease();

My code for moving rows is:

void CSortReportDlg::OnDeltaposReportSpin(NMHDR* pNMHDR, LRESULT* pResult)
{
    NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;

    int number_rows = wndReport.GetRows()->GetCount();
    int cur_item = wndReport.GetFocusedRow();
    if (pNMUpDown->iDelta > 0 && cur_item >= 0)  // Move Up
        {
        if (cur_item == 0 || cur_item >= number_rows)
            return;

        CXTPReportRow *pRow = wndReport.GetRows()->GetAt(cur_item);
        if (pRow)
            {
            wndReportGetRows()->RemoveAt(cur_item);
            wndReportGetRows()->InsertAt(cur_item - 1, pRow);
            }
        }
    else if (pNMUpDown->iDelta < 0 && cur_item >= 0 && cur_item < (number_rows - 1))  // Move Down
        {
        if (number_rows == 0 || cur_item == number_rows || cur_item >= number_rows-1)
            return;

        CXTPReportRow *pRow = wndReport.GetRows()->GetAt(cur_item);
        if (pRow)
            {
            wndReportGetRows()->RemoveAt(cur_item);
            wndReportGetRows()->InsertAt(cur_item + 1, pRow);
            }
        }

    *pResult = 0;
}

Have I missed some other function call I must make after moving the rows?
Back to Top
sserge View Drop Down
Moderator Group
Moderator Group


Joined: 01 December 2004
Status: Offline
Points: 1297
Post Options Post Options   Thanks (0) Thanks(0)   Quote sserge Quote  Post ReplyReply Direct Link To This Post Posted: 09 July 2006 at 8:57am
Hi,

RemoveAt calls InternalRelease for a removed row, unlike InsertAt, which assumes recently created row object. So far, it looks like you have to add pRow->InternalAddRef(); as a first operation in if (pRow) {...

--
WBR,
Serge
Back to Top
rock View Drop Down
Groupie
Groupie


Joined: 27 October 2005
Status: Offline
Points: 19
Post Options Post Options   Thanks (0) Thanks(0)   Quote rock Quote  Post ReplyReply Direct Link To This Post Posted: 10 July 2006 at 11:58am
Serge,

That appears to have done it.  It works fine now.

Thanks
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.155 seconds.