Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS General Discussion » Selecting a row in a the grid Collapse All
Subject Author Date
Fergal Moran Mar 5, 2004 - 11:12 AM

Hi Guys


Congrats on the new grid control.  It is very nice - looking forward to the documentation :)


I have the grid working now finally - however I wish to know how to highlight a particular row based on a mouse point (in a right click event) and then get the value in a particular column in that highlighted row - something like


  int nCol = 0;
  int nRow = GetRowAtPoint(point);
  char* szVal = GetText(nRow, nCol);


Thanks guys


Fergal.

Technical Support Mar 9, 2004 - 4:32 AM

Dear Fergal,


To make your grid highlight the rows under the mouse pointer, you should invoke the following method in the grid initialization code:


m_wndGrid.HoverHighlightSet(
      true,
      false,
      false,
      false,
      true,
      false
      );


Now let’s get to how to get the cell value. The cells are implemented as the cell objects which are instances of the CExtGridCell class (or can be derived from it). First, you need to get a pointer to the cell object at the specified position:

 
CExtGridCell * pCell =
      m_wndGrid->GridCellGet( nColNo, nRowNo );
if( pCell != NULL )
{
      CString s;
      pCell->TextGet( s );
}
 


The pointer will be NULL if you have not inserted any value yet. This is similar to the NULL values in database tables.


The following code

CExtGridCell * pCell =
      m_wndGrid->GridCellGet(
            nColNo, nRowNo, 0, 0,
            RUNTIME_CLASS(CExtGridCellStringDM )
            );


allows you to get a pointer to the existing cell at the specified position or a newly created CExtGridCellStringDM object if this location is empty. CExtGridCellStringDM implements a cell that is able to keep and display text. You may use CExtGridCellVariant objects to keep any VARIANT data values inside cells. The CExtGridCell::TextGet() method is virtual. In case of the VARIANT cells, it returns the text representation of the VARIANT data allowing for the current locale settings. TextGet() returns a copy of the cell data in the CString object. You may use the CExtGridCell::GetTextBuffer() method to get a LPCTSTR pointer to the internal text buffer of the cell. This method may be used for string cells (CExtGridCellStringDM) which have internal text buffer and cannot be used with the VARIANT cells (CExtGridCellVariant).

The CExtGridWnd::GridCellGet() method returns NULL and generates an assertion if you call it for the grid control with a cacheable data provider attached and try to get a cell pointer outside the visible page of the displayed recordset. If you use the grid control with the default internal data provider that keeps all the cells in the memory, you can get a pointer to any cell.

Fergal Moran Mar 9, 2004 - 5:55 AM

This looks great guys - big help.


However - I am still a little unclear on how I convert my mouse point to a grid row or get the currently highlighted row in the grid in order to pass it into GridCellGet.  I can’t see any members/methods in the CExtGridWnd that allow me to do this.


Regards


Fergal.

Technical Support Mar 9, 2004 - 6:36 AM

Dear Fergal,


First, you should determine which part of the grid window is covered by the mouse pointer (a.k.a. hit-testing). Second, if the hit-testing points to any inner cell, we just get a pointer to this cell. Here is the source code:


// ptClient is the mouse pointer position
// in client coordinates of the grid window
CPoint ptClient;
. . .
CExtGridHitTestInfo htInfo( ptClient );
m_wndGrid.HitTest( htInfo, false, false );
if(         (htInfo.m_dwAreaFlags & __EGBWA_INNER_CELLS) != 0
      &&    htInfo.m_nColNo >= 0L
      &&    htInfo.m_nRowNo >= 0L
      )
{
      CRuntimeClass * pInitRTC = NULL; // or set it
      // equal to RUNTIME_CLASS( CExtGridCell . . . )
      CExtGridCell * pCell =
            m_wndGrid.GridCellGet( htInfo, pInitRTC );
      . . .
}



As you see, this code uses yet another version of the CExtGridWnd::GridCellGet() method with the reference to the hit-testing information object (an instance of the CExtGridHitTestInfo class) as its parameter. With this method as well as with the previously described method, you can also initialize instances of the cell object on-the-fly.

Fergal Moran Mar 9, 2004 - 6:53 AM

Perfect - thanks a lot guys.


Again great control..