Hail all,
I'm using ADO DC together Microsoft DataGrid Control in my existing C++/MFC application. At the moment I urgently need to create tree-like view in this grid (something like in Microsoft Access when viewing related tables - when you could open/collapse child recordsets by clicking on [+] in rows of parent recordset).
Do anyone have an idea ho to implement it using Microsoft DataGrid Control ???
Below is the code illustrating how I bind grid to ADO recordset (m_pGrid is an object of wrapper-class CDataGrid):
And the following is the way i use to open ADO data source (m_ctlADODC encapsulates Microsoft ADODC Control,Code:C_Recordset& rc=m_ctlADODC.GetRecordset(); m_pGrid.SetRefDataSource(NULL); m_pGrid.SetRefDataSource(rc); m_pGrid.SetAllowAddNew(FALSE);// allow empty '*'-field at top m_pGrid.SetAllowUpdate(FALSE);// disallow editing current records m_pGrid.SetAllowDelete(FALSE);// disallow deleting by pressing Del m_pGrid.SetAllowArrows(TRUE); // allow arrows keys m_pGrid.Refresh(); m_pGrid.UpdateData();
an object of wrapper-class CAdodc):
What should I do to use tree view and multiple data sources?Code:CHAR szTemp[256]; ::sprintf(szTemp,"SELECT * FROM [%s] ORDER BY [%s]",table_db_dao,field_id); m_ctlADODC.SetConnectionString(NULL); m_ctlADODC.SetMaxRecords(ADODC_MAX_RECORDS); m_ctlADODC.SetCacheSize(ADODC_CACHE_SIZE); m_ctlADODC.SetRecordSource(NULL); lstrcat(szConnectionString,GetDocument()->GetPathName()); lstrcat(szConnectionString,_T(";")); m_ctlADODC.SetConnectionString(szConnectionString); m_ctlADODC.SetRecordSource(_T(szTemp)); m_ctlADODC.SetCursorType(adOpenDynamic); // don't use adLockBatchOptimistic since Grid refresh works badly with it m_ctlADODC.SetLockType(adLockOptimistic); m_ctlADODC.SetCommandType(adCmdTable); // use adCmdTable for table command type m_ctlADODC.SetCommandType(adCmdText); m_ctlADODC.SetBackColor(ADODC_COLOR); m_ctlADODC.SetCaption(_T("Navigation")); // if here an error with code DISP_E_EXCEPTION=0x80020009 occurs, check // the Connection String for invalid value m_ctlADODC.Refresh();
Thanks a lot in advance.....




Reply With Quote