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 » CExtGridWnd::RowInsert() Problem Collapse All
Subject Author Date
David Coleman Jul 26, 2005 - 6:04 AM

Hello,


I am having a problem with the CExtGridWnd::RowInsert() function in that it doesn’t appear to be inserting a new row when I tell it to!!!


Let me explain the scenario. My application first starts up with a splitter window containing a grid on the left and other program controls on the right. This grid is working absolutely fine. At a certain point in the program I then attempt to open up a new CMdiChildWnd also with a splitter window and containing another grid on the left and other program controls on the right. For some strange reason the RowInsert function is failing on this second window!!! I have confirmed this by call RowCountGet() which returns -1. The grid is definitely being initialised correctly as all the column headers are being displayed - I just can’t seem to insert any rows!!!


Can you offer any advice as to why this may not be working as expected???


Regards,


David.


 


 


 

Technical Support Jul 26, 2005 - 6:59 AM

The CExtGridWnd::RowCountGet() method returns a greater or equal to zero number of rows for the grid window which completely manages a two dimensional array of CExtGridCell objects in the application memory. That is the default behavior of the CExtGridWnd class. The CExtGridWnd::RowCountGet() method returns a negative value in the two cases that follow. First, the vertical scrolling strategy is set to virtual (__ESIW_ST_VIRTUAL). The virtual scrolling permits the thumb button to be only at the home, middle, or end position. This scrolling mode used for working with data of an unknown number of rows and/or columns. The AdoRecorsetView sample application allows you to browse database records in the virtual mode. The virtual scrolling mode requires a custom data provider component to be created and attached to the grid window. If you do not use the virtual scrolling and custom data providers in your application, then we may guess your code simply initializes the grid window incorrectly by specifying some invalid style flags. You may send us your project so that we can clarify the problem.

David Coleman Jul 26, 2005 - 10:11 AM

I am populating the grid in the OnInitialUpdate() on both child windows. The code is very similar in structure and so there is no logical reason as to why it should work fine on the first and not on the second!


Please give me a more logical answer with which I can actually make progress...


 

Technical Support Jul 26, 2005 - 11:52 AM

We just explained what may mean a negative value returned from the CExtGridWnd::RowInsert(). To provide you with a problem solution, we need more details about your application. Debugging your project is the most convenient way for us. At least, we need to take a look at the source code of the OnInitDialog() method which initializes the grid window that causes the problem.

David Coleman Jul 27, 2005 - 3:56 AM

Unfortunately I cannot provide the entire code for the application but I have included below the relevant code snippets relating to the grid definition and initialisation.


Hope this helps,


David.


 


 



// --- CHistoryGrid class definition


CHistoryGrid::CHistoryGrid()
 : m_nBkType( 1 )
{
 HoverEventsSet(true, true);
 HoverHighlightSet(true,false,false,false,true,false);


 SiwModifyStyleEx(
  __EGWS_EX_PM_COLORS
  //|__EGBS_EX_CELL_TOOLTIPS_OUTER
  |__EGBS_EX_CELL_EXPANDING_INNER,
  0,
  false
 );
}


 


// --- Relevant CHistoryGrid functions


void CHistoryGrid::SetCellHeader(long colNo, CString text, long width, long style) {
 CExtGridCellHeader * pCell = STATIC_DOWNCAST(
  CExtGridCellHeader,
  GridCellGetOuterAtTop(
   colNo,
   0L,
   RUNTIME_CLASS(CExtGridCellHeader)
  )                 
 );      
 pCell->ExtentSet(width);
 pCell->TextSet(text);
  
 pCell->ModifyStyle(style, 0);
}


void CHistoryGrid::SetCell(long colNo, long rowNo, CString text, long style, CString data) {
 CHistoryCell* pCell =
  STATIC_DOWNCAST(
   CHistoryCell,
   GridCellGet(colNo,rowNo,0,0,RUNTIME_CLASS(CHistoryCell))
  );
 
 if(pCell != NULL) {


  if(!text.IsEmpty())
   pCell->TextSet(text);
 
  pCell->ModifyStyle( style );
 
  if(!data.IsEmpty())
   pCell->m_Data = data; 
 }
}


void CHistoryGrid::SetCell(long colNo, long rowNo, CString text, COLORREF textColour, COLORREF bgndColour, long style, CString data) {
 CHistoryCell* pCell =
  STATIC_DOWNCAST(
   CHistoryCell,
   GridCellGet(colNo,rowNo,0,0,RUNTIME_CLASS(CHistoryCell))
  );


 if(pCell != NULL) {
 
  if(!text.IsEmpty())
   pCell->TextSet(text);


  if(textColour != NULL)
   pCell->m_TextColour = textColour;
  if(bgndColour != NULL)
   pCell->m_BgndColour = bgndColour;
 
  pCell->ModifyStyle( style );
 
  if(!data.IsEmpty())
   pCell->m_Data = data; 
 }
}


 


// --- Grid DDX control mapping in HistoryReportView.cpp:


DDX_Control(pDX, IDC_HISTORY_LIST, m_Grid);


 


// --- Grid definition in HistoryReportView.h:


CHistoryGrid m_Grid;


 


// --- Grid initialisation


void CHistoryReportView::OnInitialUpdate()
{
 CFormView::OnInitialUpdate();


 //


 CMyApp* pApp = (CMyApp*)AfxGetApp(); 


 CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd();


 CString sTemp;
 CString sTemp2;


 CTime* cTime;


 CTimeSpan* cTimeSpan;
 CTimeSpan* cTimeSpan2;
 CTimeSpan* cTimeSpan3;
 CTimeSpan* cTimeSpan4;


 SYSTEMTIME sysTime;
 COleDateTime* vDateTime;
 COleDateTime* vDateTime1;
 COleDateTime* vDateTime2;


 CString sTime;
 CString sDateTime, sDateTime2;


 CString sOldDate, sNewDate;


 CTime* cDateTime;
 CTime* cDateTime2;


 CTimeSpan cJourneyTimeSpan;
 CString sJourneyDuration;


 CTimeSpan cStopTimeSpan;
 CString sStopDuration;


 CString sDate, sDate2;
 CString sSpeed;
 CString sHeading;
 CString sLocation;


 CString sDistance;
 CString sDuration;
 CString sDurationDays, sDurationHours, sDurationMins, sDurationSecs;


 double dSpeed;
 double dDistance;


 CString columnName;


 long iItem;
 int iIndex = -1;
 int iTemp;


 float fSpeedDivider;
 float fDistanceDivider;


 //


 if(pApp->m_MeasurementUnits == "Miles") {
  fSpeedDivider = 2.23694f;
  fDistanceDivider = (0.6214f / 1000);
 }


 if(pApp->m_MeasurementUnits == "Kilometres") {
  fSpeedDivider = 3.6f;
  fDistanceDivider = (1.0f / 1000);
 }


 //


 m_HistoryReportType = pMainFrame->m_HistoryReportType;
 m_ReportData = pMainFrame->m_ReportData;


 m_RecordCount = 0;


 m_UserEarliestDate = pMainFrame->m_UserEarliestDate;
 m_UserEarliestTime = pMainFrame->m_UserEarliestTime;
 m_UserLatestDate = pMainFrame->m_UserLatestDate;
 m_UserLatestTime = pMainFrame->m_UserLatestTime;


 m_UserID = pMainFrame->m_UserID;
 m_UserName = pMainFrame->m_UserName;
 m_UserESN = pMainFrame->m_UserESN;
 m_UserIconFile = pMainFrame->m_UserIconFile;


 // set grid styles


 m_Grid.SiwModifyStyle(
  __ESIS_STH_PIXEL
  //|__ESIS_STV_ITEM
  //|__EGBS_SFM_FULL_ROWS
  //|__EGBS_NO_HIDE_SELECTION
  |__EGBS_GRIDLINES
  ,__ESIW_ST_VIRTUAL, false
 );


 // initialise list columns


 m_Grid.OuterRowCountTopSet( 1L, false );
 
 columnName.LoadString(IDS_COLUMN_DATE);
 m_Grid.ColumnAdd(1, false);
 m_Grid.SetCellHeader(0, columnName, 120, __EGCS_TA_HORZ_CENTER);


 //


 m_Grid.ColumnAdd(5, false);


 columnName.LoadString(IDS_COLUMN_LOCATION);
 m_Grid.SetCellHeader(1, columnName, 130, 0);
 
 columnName.LoadString(IDS_COLUMN_SPEED);
 m_Grid.SetCellHeader(2, columnName, 60, __EGCS_TA_HORZ_CENTER);


 columnName.LoadString(IDS_COLUMN_I1);
 m_Grid.SetCellHeader(3, columnName, 30, __EGCS_TA_HORZ_CENTER);


 columnName.LoadString(IDS_COLUMN_I2);
 m_Grid.SetCellHeader(4, columnName, 30, __EGCS_TA_HORZ_CENTER);


 columnName.LoadString(IDS_COLUMN_I3);
 m_Grid.SetCellHeader(5, columnName, 30, __EGCS_TA_HORZ_CENTER);
 
 //


 m_Grid.RowRemoveAll();


 m_SelectedItem = -1;
 
 if(m_UserID != 0) {


  if(m_UserEarliestDate != "" && m_UserLatestDate != "") {


   sTemp.Format("SELECT * FROM [History] WHERE [UserID]=%ld AND (DateValue([FixDateTime]) BETWEEN #%s# AND #%s#) ORDER BY [FixDateTime]", 
    m_UserID,
    m_UserEarliestDate,
    m_UserLatestDate,
   
   ); 
  } else {
   sTemp.Format("SELECT * FROM [History] WHERE [UserID] = %ld ORDER BY [FixDateTime]", m_UserID);
  }
  


  //


// --- Display History Report ---


 
 // initialise recordset


 pApp->m_rsODBC_History->m_strSort = ""; 
 pApp->m_rsODBC_History->m_strFilter = "";
 pApp->m_rsODBC_History->Open(AFX_DB_USE_DEFAULT_TYPE, sTemp);


 // fill list ctrl from database


 if(!pApp->m_rsODBC_History->IsEOF()) {


  iItem = 0;
  pApp->m_rsODBC_History->MoveFirst();


  while(!pApp->m_rsODBC_History->IsEOF()) {


   cTime = new CTime();
   cTime = &(pApp->m_rsODBC_History->m_FIXDATETIME);   


   sDate = cTime->Format("%d/%m/%Y %H:%M:%S");
     
   //
     
   if(pApp->isHistoryInRange(cTime, m_ReportData)) {


    m_Grid.RowInsert(iItem, 1, false);
    //m_Grid.RowAdd(1, false);


    //sTemp.Format("Rows: %ld", m_Grid.RowCountGet());
    //AfxMessageBox(sTemp, MB_OK, 0);


    dSpeed = (double)(pApp->m_rsODBC_History->m_SPEED);
    dSpeed *= fSpeedDivider;


    sSpeed.Format("%3.2f", dSpeed);


    sTemp.Format("%ld",pApp->m_rsODBC_History->m_ID);
    
    // set date
    m_Grid.SetCell(0L, iItem, sDate, 0, sTemp);
    sLocation = pApp->m_rsODBC_History->m_LOCATION;


    // set speed


    m_Grid.SetCell(1L, iItem, sLocation, 0, "");  // set location
    m_Grid.SetCell(2L, iItem, sSpeed, 0, "");  // set speed


    if(pApp->m_rsODBC_History->m_INPUTS & 0x2)  // set input #1
     m_Grid.SetCell(3L, iItem, "Off", RGB(255,255,255), RGB(255,0,0), 0, "");
    else
     m_Grid.SetCell(3L, iItem, "On", RGB(255,255,255), RGB(0,255,0), 0, "");


    if(pApp->m_rsODBC_History->m_INPUTS & 0x4)  // set input #2
     m_Grid.SetCell(4L, iItem, "Off", RGB(255,255,255), RGB(255,0,0), 0, "");
    else
     m_Grid.SetCell(4L, iItem, "On", RGB(255,255,255), RGB(0,255,0), 0, "");


    if(pApp->m_rsODBC_History->m_INPUTS & 0x8)  // set input #3
     m_Grid.SetCell(5L, iItem, "Off", RGB(255,255,255), RGB(255,0,0), 0, "");
    else
     m_Grid.SetCell(5L, iItem, "On", RGB(255,255,255), RGB(0,255,0), 0, "");
        
    //
 
    iItem++;
 
    m_RecordCount++;
   }


   //


   pApp->m_rsODBC_History->MoveNext();
  } 
 }


 // Close ODBC recordset
 
 try {
  pApp->m_rsODBC_History->Close();
 }
 catch (CDBException* e) {
  //AfxMessageBox(e->m_strError, MB_OK, 0); 
  pApp->WriteError(e->m_strError);


  e->Delete();
 }


// ----------------


 //


 m_Grid.ShowWindow(SW_SHOW);


 CWnd::RepositionBars( 0, 0xFFFF, IDC_HISTORY_LIST);           
 m_Grid.OnSwUpdateScrollBars();     
 m_Grid.OnSwDoRedraw();


}

Technical Support Jul 27, 2005 - 8:57 AM

Here is the code snippet from your message:

m_Grid.SiwModifyStyle(
   __ESIS_STH_PIXEL 
   //|__ESIS_STV_ITEM
   //|__EGBS_SFM_FULL_ROWS
   //|__EGBS_NO_HIDE_SELECTION
   |__EGBS_GRIDLINES
   ,__ESIW_ST_VIRTUAL, false
   );
Please uncomment the __ESIS_STV_ITEM flag in it. We recommend you specify the scrolling strategies explicitly.

David Coleman Jul 27, 2005 - 9:36 AM

I have changed the code snippet above to:


m_Grid.SiwModifyStyle(


__ESIS_STH_PIXEL


|__ESIS_STV_ITEM


//|__EGBS_SFM_FULL_ROWS


//|__EGBS_NO_HIDE_SELECTION


|__EGBS_GRIDLINES


,__ESIS_STV_VIRTUAL,false


);


 


as suggested but still no success! The row count is still being returned as -1 and no rows are added! Interestingly if I move all the initialisation code to the OnCreate function the row count increases as new rows are added but the grid is not displayed - not even the header cells!


 


Why does it work fine on one child window and not another???


 


Regards,


David.

Technical Support Jul 27, 2005 - 1:46 PM

At this point we see two ways to solve this problem:

A) You will send us source code of the class that creates the grid control and initializes it unsuccessfully.

B) You will contact us by e-mail or phone call so that we can arrange a web conference which will allow us to fix the problem without sending us any source code.

David Coleman Jul 28, 2005 - 9:08 AM

After closer inspection I’ve tracked down and corrected the problem :)


 


For some reason on the second child window I had used:


__ESIW_ST_VIRTUAL


 


instead of __ESIS_STV_VIRTUAL


 


I corrected this and it now works as expected!


David.

David Coleman Jul 28, 2005 - 3:46 AM

Please advise as to how we can setup a web conference

Technical Support Jul 28, 2005 - 9:07 AM

We sent you instructions on the issue of remote debugging by e-mail.

David Coleman Jul 28, 2005 - 9:09 AM

<TABLE style="BORDER-COLLAPSE: collapse" cellSpacing=0 cellPadding=4 width="100%" border=0>
<TBODY>
<TR id=_ctl13_Buttons>
<TD class=forum_line3 align=right>Reply  </TD></TR>
<TR>
<TD class=forum_line3 id=_ctl13_MessageText>

After closer inspection I’ve tracked down and corrected the problem :)



 



For some reason on the second child window I had used:



__ESIW_ST_VIRTUAL



 



instead of __ESIS_STV_VIRTUAL



 



I corrected this and it now works as expected!



David.

</TD></TR></TBODY></TABLE>

Technical Support Jul 28, 2005 - 1:10 PM

You are absolutely right and we are sorry that we did not find this tipe at once. The __ESIW_ST_VIRTUAL constant is really not a style flag. It is defined for use with the CExtScrollItemWnd::SiwScrollTypeHGet(), CExtScrollItemWnd::SiwScrollTypeHSet(), CExtScrollItemWnd::SiwScrollTypeVGet() and CExtScrollItemWnd::SiwScrollTypeVSet() methods.