Document directory
- The above setgriditem (pdispinfo); this function is a defined function for displaying data. pdispinfo points to the struct.
For GIS software, attribute data display is an important issue. In the underlying GIS development based on VC ++, clistctrl or DBGrid is generally used to display attribute data. However, if the display efficiency of these controls is relatively low or the efficiency is high, it is more difficult to operate. Through recent explorations, we found a better grid control to display attribute data.
Cgridctrl is a control made public by source code. You can modify the source code by yourself. Control features:
● You can use the mouse to select a cell, or use the CTRL and shift keys to select a cell.
Select. You can also cancel the selection.
● The rows and columns can be rearranged by size, and the rows, columns, or both can be unordered.
● Double-click to differentiate points. Rows or columns can be automatically sorted by size.
● Fixed to any column or row
● Cells can have personalized settings with different text and background colors
● Cells can be individually set with fonts
● Cells can be marked with "read-only" or other status settings and Detection
● OLE drag and drop
● Ctrl-C, Ctrl-X, and Ctrl-V copy, cut, and paste operations, and Ctrl-a select all
● When the cell becomes the focus and you press the character key in the cell editing area
The cell is edited.
● Supports Microsoft's smart mouse
● Images can be added to cells.
● The "virtual" mode can be used for large data
● Adequate printing support, supporting the document/browsing environment (including print preview) or session-based applications (not supporting print preview)
● Optional "list mode", including Selecting All or single rows, and clicking the column title prompt to insert rows.
● A large number of virtual functions can easily expand functions of controls
● Unicode
● Supports WinCE
● The cell title prompt is too small to display data
● You can hide rows and columns.
● Compilation in vc4.2, 5.0, 6.0, and Ce Toolkit 2.0 and 3.0 demonstrates most of the feature documents in the grid control.
If you want to use this grid control in your project, you have to add some files in your project:
Gridctrl. cpp, gridctrl. H grid control resource file and header file
Gridcellbase. CPP, the base class of the gridcellbase. H Cell
Gridcell. cpp, default execution file of cells gridcell. h
Definitions of cellrange. h ccellid and ccellrange classes
Direct storage class for memdc. h Keith rule's
Inplaceedit. cpp, inplaceedit. h locate the source file and header file in the editing window
Griddroptarget. cpp, griddroptarget. h The drag and drop objects of the Grid container are necessary only when gridcontrol_no_dragdrop is not defined in gridctrl. h.
Titletip. cpp, titletip. h indicates the title of the cell from Zafir Anjum. The structure is necessary only when gridcontrol_no_titletips is not defined in gridctrl. h.
This grid is based on a framework (cgridctrl project) that organizes and controls the actions of cells that hold data and execute certain operations, such as drawing, handling methods, such as button click events. The handle event of the grid project itself, such as a response before the cell is clicked, will also send some mouse information if it thinks it is necessary. It also contains a drag object (cgriddroptarget) and a title prompt object (ctitletip), the former handles the drag operation, the latter can display its content when the physical space of a cell is insufficient to display its content to the maximum extent. A grid cell can be of any type, and its length is the same as that of the class originating from cgridbasecell. The package contains a cgridcell class that can process basic data storage and editing operations. The expanded two classes cgridcellcombo and cgridurlcell demonstrate how to create your own cell class.
Step 1: load the control. Add a custom control to the dialog box and set the class to mfcgridctrl. Step 2: Initialize the control.
Int nfieldcnt = m_player-> getlayerdefn ()-> getfieldcount (); // Number of columns m_ctrlattrtable.setvirtualmode (true); m_ctrlattrtable.seteditable (false); values (gvs_data); values (RGB, 0xff, 0xe0); // yellow background m_ctrlattrtable.setrowcount (m_player-> getfeaturecount () + 1); // initially 10 rows m_ctrlattrtable.setcolumncount (nfieldcnt + 2 ); // initialize to the number of fields + 2 columns m_ctrlattrtable.setfixedrowcount (1); // the header is a row // values (1); // the header is a column m_ctrlattrtable.setlistmode (); m_ctrlattrtable.setrowresize (1 ); m_ctrlattrtable.setcolumnresize (1 );
From the code above, we can see that this control supports Virtual Mode. We need to use this feature to display a large amount of attribute data. This function m_ctrlattrtable.setvirtualmode (true); Step 3: Reload the ony y message response function of the parent window
BOOL CAttrTableDlg::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult){// TODO: Add your specialized code here and/or call the base classif (wParam == (WPARAM)m_ctrlAttrTable.GetDlgCtrlID()){*pResult = 1;GV_DISPINFO *pDispInfo = (GV_DISPINFO*)lParam;if (GVN_GETDISPINFO == pDispInfo->hdr.code){SetGridItem(pDispInfo);return TRUE;}else if (GVN_ODCACHEHINT == pDispInfo->hdr.code){GV_CACHEHINT *pCacheHint = (GV_CACHEHINT*)pDispInfo;TRACE(_T("Cache hint received for cell range %d,%d - %d,%d\n"),pCacheHint->range.GetMinRow(),pCacheHint->range.GetMinCol(),pCacheHint->range.GetMaxRow(),pCacheHint->range.GetMaxCol());}}return CDialog::OnNotify(wParam, lParam, pResult);}
The above setgriditem (pdispinfo); this function is a defined function for displaying data. pdispinfo points to the struct typedef struct taggv_dispinfo {
Nmhdr;
Gv_item item;
} Gv_dispinfo;
Pointer, which includes some basic information about cells.
Step 4: Display Data
Int cattrtabledlg: setgriditem (gv_dispinfo * pdispinfo) {// set the table display attribute int ROW = pdispinfo-> item. row; int Col = pdispinfo-> item. col; If (row <1) // set 0 rows to show the header {pdispinfo-> item. nformat = dt_center | dt_wordbreak; If (COL> = 2) // Its field name {pdispinfo-> item. strtext. format (cstring (m_player-> getlayerdefn ()-> getfielddefn (Col-2)-> getnameref ();} else if (COL = 0) {pdispinfo-> item. strtext = _ T ("FID");} else if (COL = 1) {pdispinfo-> item. strtext = _ T ("shape *") ;}} else {pdispinfo-> item. nformat = dt_center | dt_vcenter | dt_singleline | dt_end_ellipsis; If (COL> = 2) // The value of the field itself {pdispinfo-> item. strtext. format (cstring (m_player-> getfeature (Row-1)-> getfieldasstring (Col-2);} else if (COL = 0) {pdispinfo-> item. strtext. format (_ T ("% d"), m_player-> getfeature (Row-1)-> getfid ();} else if (COL = 1) {pdispinfo-> item. strtext = cstring (m_player-> getfeature (Row-1)-> getgeometryref ()-> getgeometryname () ;}} return 0 ;}
The final result is as follows:
A total of 7603 records will soon be displayed. I think this internal principle is to use high-speed cache. In fact, the control itself does not store data. It is intended to be useful for GIS development or database developers. If you have any comments, you can share them with us. Thank you.