Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Report Control
  New Posts New Posts RSS Feed - CXTPReportRecords::Move doubt
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

CXTPReportRecords::Move doubt

 Post Reply Post Reply
Author
Message
znakeeye View Drop Down
Senior Member
Senior Member
Avatar

Joined: 26 July 2006
Status: Offline
Points: 1672
Post Options Post Options   Thanks (0) Thanks(0)   Quote znakeeye Quote  Post ReplyReply Direct Link To This Post Topic: CXTPReportRecords::Move doubt
    Posted: 08 January 2009 at 9:49am

XTP 12.1.1

CXTPReportSelectedRows* pSelectedRows = m_wndReport.GetSelectedRows();
if (pSelectedRows && pSelectedRows->GetCount() == 1)
{
    pDropRecords->Add(pSelectedRows->GetAt(0)->GetRecord());
    m_wndReport.GetRecords()->Move(pSelectedRows->GetAt(0)->GetIndex() + 1, pDropRecords);

    m_wndReport.Populate();

}
 
GetIndex+1 moves the item to its current position. GetIndex+2 does what I want (moving it down one row), but that makes no sense! Am I doing anything wrong?
PokerMemento - http://www.pokermemento.com/
Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 08 January 2009 at 6:37pm

try diff way: index from Record not from Row

CXTPReportSelectedRows* pSelectedRows = GetReportCtrl().GetSelectedRows();

if (pSelectedRows && pSelectedRows->GetCount() == 1)

{

CXTPReportRecords* pDropRecords = new CXTPReportRecords(TRUE);

CXTPReportRow* pRow = pSelectedRows->GetAt(0);

CXTPReportRecord* pRec = pRow->GetRecord();

int iNd = pRow->GetIndex();

int ind = pRec->GetIndex();

pDropRecords->Add(pRec);

//GetReportCtrl().GetRecords()->Move(iNd + 1, pDropRecords);

GetReportCtrl().GetRecords()->Move(ind + 1, pDropRecords);

GetReportCtrl().Populate();

delete pDropRecords;

}

Back to Top
znakeeye View Drop Down
Senior Member
Senior Member
Avatar

Joined: 26 July 2006
Status: Offline
Points: 1672
Post Options Post Options   Thanks (0) Thanks(0)   Quote znakeeye Quote  Post ReplyReply Direct Link To This Post Posted: 09 January 2009 at 7:18am
No, same problem!
PokerMemento - http://www.pokermemento.com/
Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 09 January 2009 at 11:41am

Need some clarifications from you - Do you have report structure like main in ReportSample - where there is parent-childs rows? In such case you can only move child records and only in given child range. But in general I am right proposing use Record index - not Rows

Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 09 January 2009 at 11:10pm
What do you expect to see in ReportView after Move operation? Sometimes nothing happened because even you change index of some record in record array, the logic of ReportView rows structure and hierarchy can keep selected row in same visual position or index increase can produce position decrease. Agree?
Back to Top
znakeeye View Drop Down
Senior Member
Senior Member
Avatar

Joined: 26 July 2006
Status: Offline
Points: 1672
Post Options Post Options   Thanks (0) Thanks(0)   Quote znakeeye Quote  Post ReplyReply Direct Link To This Post Posted: 12 January 2009 at 7:33am
Row 1
Row 2
Row 3
Row 4
 
Now I want to swap "Row 3" and "Row 2". With XTP 12.1.1 this can be achieved by moving "Row 2" down two steps or moving "Row 3" up two steps. Note that I sometimes want to perform this operation with multiple rows.
 
CXTPReportRecord* pRecord = pSelectedRows->GetAt(0)->GetRecord();
pDropRecords->Add(pRecord);
m_wndReport.GetRecords()->Move(pRecord->GetIndex() + 2, pDropRecords);
 
That does the trick, but it's not logical! Is there a better way?
PokerMemento - http://www.pokermemento.com/
Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 12 January 2009 at 9:38am
Look in the source
void CXTPReportRecords::Move(int nIndex, CXTPReportRecords* pRecords)

{

ASSERT(pRecords->m_bArray == TRUE);

if (nIndex > GetCount())

nIndex = GetCount();

int nRecordsCount = (int)pRecords->GetCount(), i;

for (i = 0; i < nRecordsCount; i++)

{

CXTPReportRecord* pRecord = pRecords->GetAt(i);

int nRecordIndex = pRecord->GetIndex();

if (pRecord->m_pRecords != this)

continue;

ASSERT(pRecord && GetAt(nRecordIndex) == pRecord);

m_arrRecords.RemoveAt(nRecordIndex);

if (nRecordIndex < nIndex)

{

nIndex--;

}

for (int j = i + 1; j < nRecordsCount; j++)

{

pRecord = pRecords->GetAt(j);

if (pRecord->m_pRecords != this)

continue;

if (pRecord->GetIndex() > nRecordIndex)

{

pRecord->m_nIndex--;

}

}

}

for (i = 0; i < nRecordsCount; i++)

{

CXTPReportRecord* pRecord = pRecords->GetAt(i);

if (pRecord->m_pRecords != this)

continue;

m_arrRecords.InsertAt(nIndex, pRecord);

nIndex++;

}

UpdateIndexes();

}

void CXTPReportRecords::UpdateIndexes(int nStart /*= 0*/)

{

for (int i = nStart; i < GetCount(); i++)

GetAt(i)->m_nIndex = i;

}

Back to Top
znakeeye View Drop Down
Senior Member
Senior Member
Avatar

Joined: 26 July 2006
Status: Offline
Points: 1672
Post Options Post Options   Thanks (0) Thanks(0)   Quote znakeeye Quote  Post ReplyReply Direct Link To This Post Posted: 13 January 2009 at 2:42am
I've looked at it, and understand what happens. What I'm asking for here, is how to do this the "right" way. Should I stick to my "+2" solution?
 
Many thanks for your help!
PokerMemento - http://www.pokermemento.com/
Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 13 January 2009 at 8:33am
In flat mode - no group, no parent-child records - u can use move and trust it - I give you a source so u understand how it works. In non-flat mode - no - as logic is more complicated. I also already talked about it. ReportSample is a good example as it use groups and you can see relations between rec place and row pace is not simple
Back to Top
znakeeye View Drop Down
Senior Member
Senior Member
Avatar

Joined: 26 July 2006
Status: Offline
Points: 1672
Post Options Post Options   Thanks (0) Thanks(0)   Quote znakeeye Quote  Post ReplyReply Direct Link To This Post Posted: 13 January 2009 at 11:20am
Thanks for the clear explanation. I understand groups need some more logic for this operation.
PokerMemento - http://www.pokermemento.com/
Back to Top
mgampi View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14 July 2003
Status: Offline
Points: 1201
Post Options Post Options   Thanks (0) Thanks(0)   Quote mgampi Quote  Post ReplyReply Direct Link To This Post Posted: 28 May 2009 at 5:53pm
Originally posted by mdoubson mdoubson wrote:

try diff way: index from Record not from Row

CXTPReportSelectedRows* pSelectedRows = GetReportCtrl().GetSelectedRows();

if (pSelectedRows && pSelectedRows->GetCount() == 1)

{

CXTPReportRecords* pDropRecords = new CXTPReportRecords(TRUE);

CXTPReportRow* pRow = pSelectedRows->GetAt(0);

CXTPReportRecord* pRec = pRow->GetRecord();

int iNd = pRow->GetIndex();

int ind = pRec->GetIndex();

pDropRecords->Add(pRec);

//GetReportCtrl().GetRecords()->Move(iNd + 1, pDropRecords);

GetReportCtrl().GetRecords()->Move(ind + 1, pDropRecords);

GetReportCtrl().Populate();

delete pDropRecords;

}


Hi;
I tried this solution and I have to concede a point to znakeeye, There's definitely a bug inside the CXTPReportRecords::Move() function. Moving a record up one position works with calling Move(currentIndex-1, records), but calling Move(currentIndex+1, records) has no effect! Only calling Move(currentIndex+2 moves the row down by one position!
Taking a closer look at the source code brings up that the
if (nRecordIndex < nIndex)
{
     nIndex--;
}

needs a redesign.

I believe the code should be changed to
if (nRecordIndex < nIndex-1)
{
     nIndex--;
}


otherwise moving a row/record by an offset of +1 down never works and offsets greater +1 moves the record to the position offset-1.

BTW I have a simple flat report control, no grouping, no children only a few plain records...
Martin

Product: Xtreme Toolkit v 22.1.0, new Projects v 24.0.0
Platform: Windows 10 v 22H2 (64bit)
Language: VC++ 2022
Back to Top
znakeeye View Drop Down
Senior Member
Senior Member
Avatar

Joined: 26 July 2006
Status: Offline
Points: 1672
Post Options Post Options   Thanks (0) Thanks(0)   Quote znakeeye Quote  Post ReplyReply Direct Link To This Post Posted: 29 May 2009 at 11:03am

If you fix this, please do not forget to mention it in the release notes. Otherwise I won't see the change until my users start complaining a year later :P

PokerMemento - http://www.pokermemento.com/
Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 29 May 2009 at 11:31am
Hi, I am ready to work on this problem today but before I like you try today's version of static app with all core modifications:
 
I can drag and drop any row in any position and it works properly. This is the only place where function Move() used:
 
file XTPReportControl.cpp line 4618

GetRecords()->Move(nInsert, pDropRecords);

Please confirm it with your testing

 

Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 29 May 2009 at 1:16pm
this is a test I run in app as testfunction call from menu after you select row:

CXTPReportControl& wndReport = GetReportCtrl();

CXTPReportRecords* pDropRecords = new CXTPReportRecords(TRUE);

pDropRecords->Add(wndReport.GetRecords()->GetAt(1));

//pDropRecords->Add(wndReport.GetRecords()->GetAt(2));

CXTPReportSelectedRows* pSelectedRows = wndReport.GetSelectedRows();

if (pSelectedRows && pSelectedRows->GetCount() == 1)

{

int index = pSelectedRows->GetAt(0)->GetIndex();

CString s; s.Format(_T("Selected record index = %d"), index);

AfxMessageBox(s);

pDropRecords->Add(pSelectedRows->GetAt(0)->GetRecord());

wndReport.GetRecords()->Move(index + 1, pDropRecords);

wndReport.Populate();

}

CMDTARGET_RELEASE(pDropRecords);

and this is snapshots:
 
Back to Top
znakeeye View Drop Down
Senior Member
Senior Member
Avatar

Joined: 26 July 2006
Status: Offline
Points: 1672
Post Options Post Options   Thanks (0) Thanks(0)   Quote znakeeye Quote  Post ReplyReply Direct Link To This Post Posted: 30 May 2009 at 5:30am
Have no time to test it at the moment. However, the simpliest test is as follows:
 
Programmatically move ONE record ONE step downwards:
Move(currentIndex+1, ...);
PokerMemento - http://www.pokermemento.com/
Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 02 June 2009 at 2:43pm
It was a bug (even 2 bugs) - this is updated code already SVNed:
 
 
try menu : Test FindRecordItem (don't be confused by menu text - it just dev test) - this call will move selected row's record down on 1:
Move(index + 1,....)
 
if not enough record to make such move - index will adjust to move all selection to the end of report

void CXTPReportRecords::Move(int nIndex, CXTPReportRecords* pRecords)

{

if (pRecords->m_bArray)

{

if (nIndex < 0)

nIndex = 0;

if (nIndex >= GetCount())

nIndex = GetCount() - 1;

int nRecordsCount = (int) pRecords->GetCount(), i;

if (nIndex >= GetCount() - nRecordsCount)

nIndex = GetCount() - nRecordsCount;

for (i = 0; i < nRecordsCount; i++)

{

CXTPReportRecord* pRecord = pRecords->GetAt(i);

if (pRecord)

{

int nRecordIndex = pRecord->GetIndex();

if (pRecord->m_pRecords != this)

continue;

if (GetAt(nRecordIndex) == pRecord)

{

m_arrRecords.RemoveAt(nRecordIndex);

for (int j = i + 1; j < nRecordsCount; j++)

{

pRecord = pRecords->GetAt(j);

if (pRecord->m_pRecords != this)

continue;

if (pRecord->GetIndex() > nRecordIndex)

pRecord->m_nIndex--;

}

}

}

}

for (i = 0; i < nRecordsCount; i++)

{

CXTPReportRecord* pRecord = pRecords->GetAt(i);

if (pRecord)

{

if (pRecord->m_pRecords != this)

continue;

m_arrRecords.InsertAt(nIndex, pRecord);

nIndex++;

}

}

UpdateIndexes();

}

}

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.172 seconds.