Objective Grid: Determining the new row or column ID after a user drag

Article ID: 514
Last updated: 16 Apr, 2018
Article ID: 514
Last updated: 16 Apr, 2018
Revision: 3
Views: 1879
Posted: 09 Jan, 2001
by Meltreger B.
Updated: 16 Apr, 2018
by Meltreger B.

Problem


How can I determine the new row or column ID after the user has dragged the rows/columns?


Cause



Action


Here are some steps:

Add a user attribute. See gridsvw5.cpp in gridapp how to add a user attribute.

Also, add an array:

CDWordArray m_awOriginalCol;

At initialization time (in OnInitialUpdate()), you assign the column id to this user attribute, e.g.

for (ROWCOL nCol = 0; nCol < nCount; nCol++)
{
wsprintf(sz, _T("%d"), nCol);

SetStyleRange(CGXRange().SetCols(nCol), CGXStyle().SetUserAttribute(IDS_UA_COLID, sz));

}

Next, you override StoreMoveCols and StoreRemoveCols. In your overrides you call the base class version and after that you execute a line like the following:

for (ROWCOL nCol = 0; nCol < nCount; nCol++)
{
CGXStyle style;
GetStyleRowCol(0, nCol, style, gxCopy, -1);
m_awOriginalCol[atoi(style.GetUserAttribute(IDS_UA_COLID))] = nCol;
}

(You might also use SetItemDataPtr() and use type conversion to an integer instead of using a user attribute).

Now, whenever you want to access the original column you may call

if (m_awOriginalCol.GetSize() > nCol && m_awOriginalCol[nCol] > 0)
{
// columns have been rearranged, get original column
nCol = m_awOriginalCol[nCol];
}
GetStyleRowCol(nRow, nCol, ....);

This article was:   Helpful | Not helpful
Report an issue
Article ID: 514
Last updated: 16 Apr, 2018
Revision: 3
Views: 1879
Posted: 09 Jan, 2001 by Meltreger B.
Updated: 16 Apr, 2018 by Meltreger B.

Others in this category