// --------------- Required variables ----------------- CGridColumn *pColumn; CGridHeaderSections *pSections; CGridHeaderSection *pSection; CGridHeaderSection *pUpperSection; // ----------------- Let's add some columns -------------- m_grid.AddColumn(_T(""), 60, LVCFMT_CENTER); // , m_grid.AddColumn(_T(""), 92, LVCFMT_CENTER); m_grid.AddColumn(_T(""), 81, LVCFMT_CENTER); m_grid.AddColumn(_T(""), 68, LVCFMT_CENTER); // --------------- Set additional column properties ---------------- pColumn = m_grid.GetColumn(0); pColumn->SetTabStop(FALSE); // // --------------- Let's put the grid header into shape ------------ pSections = m_grid.GetHeader()->GetSections(); pUpperSection = pSections->GetSection(0); pUpperSection->SetCaption(_T("")); pUpperSection->SetAlignment(LVCFMT_CENTER); pUpperSection = pSections->GetSection(1); pUpperSection->SetCaption(_T("")); pUpperSection->SetAlignment(LVCFMT_CENTER); pUpperSection = pSections->GetSection(2); pUpperSection->SetCaption(_T("")); pUpperSection->SetAlignment(LVCFMT_CENTER); pUpperSection->SetWordWrap(TRUE); // 3- pSection = pUpperSection->Add(); pSection->SetCaption(_T("")); pSection->SetAlignment(LVCFMT_CENTER); pUpperSection = pSection; pUpperSection = pSection->GetParent(); pSection = pUpperSection->Add(); pSection->SetCaption(_T("")); pSection->SetAlignment(LVCFMT_CENTER); pUpperSection = pSection; pUpperSection = pSection->GetParent(); m_grid.GetHeader()->SynchronizeSections(); // -------------- Some additional initializations... ------ // CGridHeader *pHeader = m_grid.GetHeader(); pHeader->SetSectionHeight(25); // pHeader->SynchronizeSections(); m_grid.SetFixedCount(1); // m_grid.SetRowSelect(); // m_grid.SetRowHeight(25); //
struct sKlient { int nomer; COleDateTime date; CString tel; CString adres; };
vector<sKlient> m_data;
// sKlient tmp; tmp.nomer = 1; tmp.date = COleDateTime(2012,1,1,0,0,0); tmp.tel = L"12-34-56"; tmp.adres = L" 1"; m_data.push_back(tmp); tmp.nomer = 2; tmp.date = COleDateTime(2011,2,3,0,0,0); tmp.tel = L"78-12-45"; tmp.adres = L" 2"; m_data.push_back(tmp); m_grid.SetRowCount(m_data.size()); //
afx_msg void OnGridGetDispInfo(NMHDR *pNMHDR, LRESULT *pResult);
ON_NOTIFY(VGN_GETDISPINFO, IDC_CUSTOM1, OnGridGetDispInfo)
VG_DISPINFO *pDispInfo = (VG_DISPINFO *)pNMHDR; CString st; if (pDispInfo->item.mask & LVIF_TEXT) // { switch (pDispInfo->item.nColumn) { case 0: {// â„– st.Format(L"%d", m_data[pDispInfo->item.nRow].nomer); pDispInfo->item.strText = st; } break; } } // if (pDispInfo->item.mask & LVIF_COLOR) { if (pDispInfo->item.nColumn == 1) // { pDispInfo->item.pDC->SetBkColor(RGB(202, 228, 255)); } }
ON_NOTIFY(WM_LBUTTONDBLCLK, IDC_CUSTOM1, OnNMDblclkGrid) void CCVirtaGridTestDlg::OnNMDblclkGrid(NMHDR *pNMHDR, LRESULT *pResult) { int n; n = m_grid.GetRow(); if (!m_grid.GetRowCount() || (n > m_grid.GetRowCount()-1)) return; ::AfxMessageBox(m_data[n].adres); }
Source: https://habr.com/ru/post/140388/