![]() |
CXTPReportRecords::Move doubt |
Post Reply ![]() |
Author | |||
znakeeye ![]() Senior Member ![]() ![]() Joined: 26 July 2006 Status: Offline Points: 1672 |
![]() ![]() ![]() ![]() ![]() 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/
|
|||
![]() |
|||
mdoubson ![]() Senior Member ![]() ![]() Joined: 17 November 2008 Status: Offline Points: 1705 |
![]() ![]() ![]() ![]() ![]() |
||
try diff way: index from Record not from RowCXTPReportSelectedRows* 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;} |
|||
![]() |
|||
znakeeye ![]() Senior Member ![]() ![]() Joined: 26 July 2006 Status: Offline Points: 1672 |
![]() ![]() ![]() ![]() ![]() |
||
No, same problem!
|
|||
PokerMemento - http://www.pokermemento.com/
|
|||
![]() |
|||
mdoubson ![]() Senior Member ![]() ![]() Joined: 17 November 2008 Status: Offline Points: 1705 |
![]() ![]() ![]() ![]() ![]() |
||
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 |
|||
![]() |
|||
mdoubson ![]() Senior Member ![]() ![]() Joined: 17 November 2008 Status: Offline Points: 1705 |
![]() ![]() ![]() ![]() ![]() |
||
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?
|
|||
![]() |
|||
znakeeye ![]() Senior Member ![]() ![]() Joined: 26 July 2006 Status: Offline Points: 1672 |
![]() ![]() ![]() ![]() ![]() |
||
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/
|
|||
![]() |
|||
mdoubson ![]() Senior Member ![]() ![]() Joined: 17 November 2008 Status: Offline Points: 1705 |
![]() ![]() ![]() ![]() ![]() |
||
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; } |
|||
![]() |
|||
znakeeye ![]() Senior Member ![]() ![]() Joined: 26 July 2006 Status: Offline Points: 1672 |
![]() ![]() ![]() ![]() ![]() |
||
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/
|
|||
![]() |
|||
mdoubson ![]() Senior Member ![]() ![]() Joined: 17 November 2008 Status: Offline Points: 1705 |
![]() ![]() ![]() ![]() ![]() |
||
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
|
|||
![]() |
|||
znakeeye ![]() Senior Member ![]() ![]() Joined: 26 July 2006 Status: Offline Points: 1672 |
![]() ![]() ![]() ![]() ![]() |
||
Thanks for the clear explanation. I understand groups need some more logic for this operation.
|
|||
PokerMemento - http://www.pokermemento.com/
|
|||
![]() |
|||
mgampi ![]() Senior Member ![]() ![]() Joined: 14 July 2003 Status: Offline Points: 1201 |
![]() ![]() ![]() ![]() ![]() |
||
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
needs a redesign. I believe the code should be changed to
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 |
|||
![]() |
|||
znakeeye ![]() Senior Member ![]() ![]() Joined: 26 July 2006 Status: Offline Points: 1672 |
![]() ![]() ![]() ![]() ![]() |
||
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/
|
|||
![]() |
|||
mdoubson ![]() Senior Member ![]() ![]() Joined: 17 November 2008 Status: Offline Points: 1705 |
![]() ![]() ![]() ![]() ![]() |
||
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
|
|||
![]() |
|||
mdoubson ![]() Senior Member ![]() ![]() Joined: 17 November 2008 Status: Offline Points: 1705 |
![]() ![]() ![]() ![]() ![]() |
||
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:
![]() |
|||
![]() |
|||
znakeeye ![]() Senior Member ![]() ![]() Joined: 26 July 2006 Status: Offline Points: 1672 |
![]() ![]() ![]() ![]() ![]() |
||
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/
|
|||
![]() |
|||
mdoubson ![]() Senior Member ![]() ![]() Joined: 17 November 2008 Status: Offline Points: 1705 |
![]() ![]() ![]() ![]() ![]() |
||
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(); } } |
|||
![]() |
Post Reply ![]() |
|
Tweet
|
Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |