CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2002
    Posts
    8

    Question A question on ADO and Microsoft DataGrid Control

    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):

    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();
    And the following is the way i use to open ADO data source (m_ctlADODC encapsulates Microsoft ADODC Control,
    an object of wrapper-class CAdodc):

    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();
    What should I do to use tree view and multiple data sources?

    Thanks a lot in advance.....
    See you.

  2. #2
    Join Date
    Jun 2002
    Posts
    8

    Re: A question on ADO and Microsoft DataGrid Control

    I just was wondering, does nobody really have an answer to my question ????
    See you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured