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 Tech Support » _VariantAssign does it refresh the grid? Collapse All
Subject Author Date
Richard Gardner Feb 11, 2008 - 12:13 PM

Hi
I have such a code
int iRowCount = m_Grid.RowCountGet();
CExtGridCellString *pCellSymbol;
CExtGridCellDateTime *pCellDateTime;
for (i = 0; i < iRowCount; i++)
{
CExtGridCellString *pCell = STATIC_DOWNCAST(CExtGridCellString, m_Grid.GridCellGet(1, i));
pCell->TextGet(cellText);
if (cellText == pu.Symbol)
{
pCellDateTime = STATIC_DOWNCAST(CExtGridCellDateTime, m_Grid.GridCellGet(0, i));
pCellDateTime->SetDateTime(pu.TradeDateTime);

//m_Grid.Invalidate() ;
TRACE1("Time %s\n", pu.TradeDateTime.Format());
return ;
}
}

where in the loop I find the needed row, then update another’s cell value. But if I don’t call m_Grid.Invalidate() the value change is not reflected in the grid.
If I resize the dialog then I can also see value changes.
Is this is a correct behavior of the grid?
Values are coming from another 3rd party COM object and I can see them using TRACE1.

The cell was created using such a code
pCellDateTime = STATIC_DOWNCAST(CExtGridCellDateTime, m_Grid.GridCellGet(0, iRowCount, 0, 0,
RUNTIME_CLASS(CExtGridCellDateTime)));
pCellDateTime->SetMode(CExtGridCellDateTime::all);
pCellDateTime->SetTimeFormat(CExtGridCellDateTime::automatic);
pCellDateTime->SetDateTime(pu.TradeDateTime);
pCellDateTime->ModifyStyle(__EGCS_READ_ONLY, 0);
pCellDateTime->ModifyStyle(0, __EGCS_BUTTON_DROPDOWN);
when doing such a code the values are displayed correctly.

Any idea are welcome
Thx

Courtney Smith Aug 11, 2008 - 6:26 PM

Hi, I have run into this problem too. I need to update my whole grid, but when i do MywndGrid.UpdateWindow();  It still won’t update. I hope there is an easier way to update my whole grid without getting the rect for each cell?


 


Thanks,


Courtney

Technical Support Aug 12, 2008 - 1:45 PM

You should invalidate the grid control first and only then update it:

CExtGridWnd & wndGrid = . . .
      wndGrid.Invalidate();
      wndGrid.UpdateWindow();
The code above repaints the entire grid window immediately. Please note, this is not effective if you need to repaint only one or several grid cells. Youshould invalidate only cell areas and finally invoke the wndGrid.UpdateWindow();. To invalidate one cell area after modifying cell’s data you should use the following code:
// you know row/column indices
LONG nColNo = . . .
LONG nRowNo = 
// and you know where the cell is (the next both values are zeros for inner data cells)
INT nColType = . . .
INT nRowType = . . .
// now you can get rectangular area of this grid cell in the client coordinates of grid control
CRect rcInvalidate;
            if( ! wndGrid.GridCellRectsGet( nColNo, nRowNo, nColType, nRowType, NULL, &rcInvalidate ) )
            return ... // cell is outside of the visible cell range
// invalidate cell area
      wndGrid.InvalidateRect( &rcInvalidate );
The code above should be invoked for all the modified cells. Then finally you can invoke the wndGrid.UpdateWindow(); to make all the invalidated grid cells repainted immediately.

Richard Gardner Feb 12, 2008 - 11:33 AM

HI
thx for the answer. accordingly to your answer when I call _VariantAssign or SetDateTime the cell itself won’t invalidate it’s content, and to see the new values I have 2 options
1. to find GridCellRect and invalidate that rectangle
2. call wndGrid.UpdateWindow();
these solutions are ok for me.

thx for help.

Technical Support Feb 12, 2008 - 5:15 AM

The code snippets both in your project and in the COM object project contain API invocations for repainting the grid. Please let us discuss this in details. Drid cells do not know their locations in the grid window and they even do not know if they are displayed in some grid window or not. It is extremely inefficient to provide a grid cell with details about its location in the grid window because row/column insertion would need to provide a lot of cells with location changing notification. But your code should know which cell it’s accessing/modifying and only your code knows the exact location. You can get coordinates of any grid cell in the grid window using the CExtGridWnd::GridCellRectsGet() method. This method allows you to compute therectangle of theentire grid cell in client coordinates of the grid window and rectangles of any of built-in parts of the grid cell. Here is the example of how to repaint aninner data cell in the CExtGridWnd window:

LONG nColNo = ...
LONG nRowNo = ...
CExtGridWnd & wndGrid = ...
CRect rcCellExtra;
      if( ! wndGrid.GridCellRectsGet(
                  nColNo,
                  nRowNo,
                  0,
                  0,
                  NULL,
                  &rcCellExtra
                  )
            )
            return ... // grid cell is out of displayed cell range
      wndGrid.InvalidateRect( &rcCellExtra );
Please note that CExtGridWnd::GridCellRectsGet() returns a flag which indicates if the cell and/or its parts locations are computed and returned successfully. This method does not allow you to compute the cell location if a cell is outside the visible/displayed range in the grid window. So, this method does not allow you to repaint the invisible grid cells. Your code should invalidate all the modified grid cells and you can use wndGrid.UpdateWindow(); to make all the changes visible immediately on the screen. For instance, the CExtGridCellInplaceSlider grid cell draws a slider or a scroll bar control in the cell’s area, this slider/scroll bar is a custom painted and non HWND-based part of the grid cell and you can drag its thumb button like it’s the slider/scroll bar common control on some dialog. This slider/scroll bar functionality is implemented in the CExtGridCellInplaceSlider class which invalidates the slider/scroll bar grid cell and updates the grid button during the position changing of the thumb button.

The second code snippet (from COM object) in your e-mail does not explain why the grid cells and/or entire grid window become repainted. We guess the grid is invalidated in some other part of code.