MFC Grid manual

How to locate objects of C++ class in the grid?

The same C++ object can be inserted into the grid multiple times. Some rows related to the given object can be filtered or collapsed by parent items and some - cannot. Each time when you add a new object to the grid, the Dapfor::GUI::HITEM handle is returned. This handle stores object state, hierarchy position, children, etc. This handle doesn’t have to be visible. It means that the handle doesn’t need to have a row number.

There are many functions that can be used to locate C++ objects in the grid.

//If C++ object is inserted only once, you can use the following functions 
//to get a handle or to determine a row index

//Get handle
CTestClass* testClass;
Dapfor::GUI::HITEM handle = m_Grid.GetItem(testClass);

//or to get row index and context of C++ object addition
int row = m_Grid.GetRow(testClass);
Dapfor::GUI::ContextType context = m_Grid.GetContextType(testClass);

//If you have a handle, you can get row position
int row = m_Grid.GetRow(handle);
Dapfor::GUI::ContextType context = m_Grid.GetContextType(handle);

//To get a C++ object that belongs to the handle, call
Dapfor::Common::CDataObject* testClass = m_Grid.GetDataObject(handle);

//The handle that corresponds to the specified row index
Dapfor::GUI::HITEM handle = m_Grid.GetItem(1);

//The same for the fixed context
Dapfor::GUI::HITEM handle = m_Grid1.GetItem(1, Dapfor::GUI::FixedContext);

//To get C++ business object that is placed in the given row:
Dapfor::Common::CDataObject* testClass = m_Grid.GetDataObject(1);

//To get all children of an item:
Dapfor::GUI::Handles children = m_Grid.GetChildren(handle, false);

//To get all visible root nodes in the scrollable context
Dapfor::GUI::Handles children = m_Grid.GetChildren(Dapfor::GUI::GI_SCROLLABLE_ROOT, true);

//To get a parent item, call
Dapfor::GUI::HITEM parent = m_Grid.GetParent(handle);

//To get a herarchical level, call
int level = m_Grid.GetHierarchicalLevel(hItem);

For more information about Implementation of IForEach interface read "IForEach interface" that can be very useful.