📄 gridctrl.shtml
字号:
</TR>
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">BOOL SetItemState(int nRow, int nCol, UINT state)</FONT></PRE>
</TD><TD WIDTH="50%">Sets the state of the given cell. Returns TRUE on success.
See also <a href="gridctrl.shtml#GV_ITEM">GV_ITEM</a>.</TD>
</TR>
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">UINT GetItemState(int nRow, int nCol) const</FONT></PRE>
</TD><TD WIDTH="50%">Gets the state of the given cell.
See also <a href="gridctrl.shtml#GV_ITEM">GV_ITEM</a>.</TD>
</TR>
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">BOOL SetItemFormat(int nRow, int nCol, UINT nFormat)</FONT></PRE>
</TD><TD WIDTH="50%">Sets the format of the given cell. Returns TRUE on success. Default
implementation of cell drawing uses CDC::DrawText, so any of the DT_* formats are available.
See also <a href="gridctrl.shtml#GV_ITEM">GV_ITEM</a>.</TD>
</TR>
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">UINT GetItemFormat(int nRow, int nCol) const</FONT></PRE>
</TD><TD WIDTH="50%">Gets the format of the given cell (default returns a CDC::DrawText DT_* format).
See also <a href="gridctrl.shtml#GV_ITEM">GV_ITEM</a>.</TD>
</TR>
<a name="CellColours"></a>
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">BOOL SetItemBkColour(int nRow, int nCol,
COLORREF cr = CLR_DEFAULT)</FONT></PRE>
</TD><TD WIDTH="50%">Sets the background colour of the given cell. Returns TRUE on success.
See also <a href="gridctrl.shtml#GV_ITEM">GV_ITEM</a>.</TD>
</TR>
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">COLORREF GetItemBkColour(int nRow, int nCol) const</FONT></PRE>
</TD><TD WIDTH="50%">Gets the background colour of the given cell.
See also <a href="gridctrl.shtml#GV_ITEM">GV_ITEM</a>.</TD>
</TR>
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">BOOL SetItemFgColour(int nRow, int nCol,
COLORREF cr = CLR_DEFAULT)</FONT></PRE>
</TD><TD WIDTH="50%">Sets the foreground colour of the given cell. Returns TRUE on success.
See also <a href="gridctrl.shtml#GV_ITEM">GV_ITEM</a>.</TD>
</TR>
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">COLORREF GetItemFgColour(int nRow, int nCol) const</FONT></PRE>
</TD><TD WIDTH="50%">Gets the foreground colour of the given cell.
See also <a href="gridctrl.shtml#GV_ITEM">GV_ITEM</a>.</TD>
</TR>
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">BOOL SetItemFont(int nRow, int nCol, LOGFONT* lf)</FONT></PRE>
</TD><TD WIDTH="50%">Sets the font of the given cell. Returns TRUE on success.
See also <a href="gridctrl.shtml#GV_ITEM">GV_ITEM</a>.</TD>
</TR>
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">LOGFONT* GetItemFont(int nRow, int nCol) const</FONT></PRE>
</TD><TD WIDTH="50%">Gets the font of the given cell.
See also <a href="gridctrl.shtml#GV_ITEM">GV_ITEM</a>.</TD>
</TR>
</table>
<h3><a name="Operations">Operations</a></h3>
<TABLE CELLSPACING=0 WIDTH="90%">
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">int InsertColumn(LPCTSTR strHeading,
UINT nFormat, int nColumn = -1)</FONT></PRE>
</TD><TD WIDTH="50%">Inserts a column at the position given by nCol, or at
the end of all columns if nCol is < 0. <b>strHeading</b> is the column heading
and <b>nFormat</b> the format. Returns the position of the inserted column.</td>
</TR>
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">int InsertRow(LPCTSTR strHeading, int nRow = -1)</FONT></PRE>
</TD><TD WIDTH="50%">Inserts a row at the position given by nRow, or at
the end of all rows if nRow is < 0. <b>strHeading</b> is the row heading.
The format of each cell in the row will be that of the cell in the first
row of the same column. Returns the position of the inserted row.</td>
</TR>
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">BOOL DeleteColumn(int nColumn)</FONT></PRE>
</TD><TD WIDTH="50%">Deletes column "nColumn", return TRUE on success.</td>
</TR>
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">BOOL DeleteRow(int nRow)</FONT></PRE>
</TD><TD WIDTH="50%">Deletes row "nRow", return TRUE on success.</td>
</TR>
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">BOOL DeleteAllItems()</FONT></PRE>
</TD><TD WIDTH="50%">Deletes all rows and contents in the grid.</td>
</TR>
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">BOOL DeleteNonFixedRows()</FONT></PRE>
</TD><TD WIDTH="50%">Deletes all non-fixed rows in the grid.</td>
</TR>
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">BOOL AutoSizeRow(int nRow)</FONT></PRE>
</TD><TD WIDTH="50%">Auto sizes the row to the size of the largest item.</td>
</TR>
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">BOOL AutoSizeColumn(int nCol)</FONT></PRE>
</TD><TD WIDTH="50%">Auto sizes the column to the size of the largest item.</td>
</TR>
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">void AutoSizeRows()</FONT></PRE>
</TD><TD WIDTH="50%">Auto sizes all rows.</td>
</TR>
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">void AutoSizeColumns()</FONT></PRE>
</TD><TD WIDTH="50%">Auto sizes all columns.</td>
</TR>
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">void AutoSize()</FONT></PRE>
</TD><TD WIDTH="50%">Auto sizes all rows and columns.</td>
</TR>
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">void ExpandColumnsToFit()</FONT></PRE>
</TD><TD WIDTH="50%">Expands the column widths to fit the grid area.</td>
</TR>
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">void ExpandRowsToFit()</FONT></PRE>
</TD><TD WIDTH="50%">Expands the row heights to fit the grid area.</td>
</TR>
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">void ExpandToFit()</FONT></PRE>
</TD><TD WIDTH="50%">Expands the rows and columns to fit the grid area.</td>
</TR>
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">CSize GetTextExtent(LPCTSTR str,
BOOL bUseSelectedFont = TRUE)</FONT></PRE>
</TD><TD WIDTH="50%">Gets the extent of the text pointed to by str. By default this uses
the selected font (which is a bigger font).
</td>
</TR>
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">void SetRedraw(BOOL bAllowDraw,
BOOL bResetScrollBars = FALSE)</FONT></PRE>
</TD><TD WIDTH="50%">Stops/starts redraws on things like changing the number of
rows and columns and autosizing, but not for user-intervention such as resizes.</td>
</TR>
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">BOOL RedrawCell(int nRow, int nCol, CDC* pDC = NULL)</FONT></PRE>
</TD><TD WIDTH="50%">Redraws the given cell. Drawing will be via the pDC
if one is supplied.</td>
</TR>
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">BOOL RedrawCell(const CCellID& cell, CDC* pDC = NULL)</FONT></PRE>
</TD><TD WIDTH="50%">Redraws the given cell. Drawing will be via the pDC
if one is supplied.</td>
</TR>
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">BOOL RedrawRow(int row)</FONT></PRE>
</TD><TD WIDTH="50%">Redraws the given row.</td>
</TR>
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">BOOL RedrawColumn(int col)</FONT></PRE>
</TD><TD WIDTH="50%">Redraws the given column.</td>
</TR>
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">CCellRange GetCellRange()</FONT></PRE>
</TD><TD WIDTH="50%">Gets the range of cells for the entire grid.
See also <a href="gridctrl.shtml#CCellRange">CCellRange<a>.</TD>
</TR>
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">void SetSelectedRange(const CCellRange& Range,
BOOL bForceRepaint = FALSE);</FONT></PRE>
</TD><TD WIDTH="50%">Sets the range of selected cells.
See also <a href="gridctrl.shtml#CCellRange">CCellRange<a>.</TD>
</TR>
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">void SetSelectedRange(int nMinRow, int nMinCol,
int nMaxRow, int nMaxCol,
BOOL bForceRepaint = FALSE);</FONT></PRE>
</TD><TD WIDTH="50%">Sets the range of selected cells.</td>
</TR>
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">BOOL IsValid(int nRow, int nCol)</FONT></PRE>
</TD><TD WIDTH="50%">Returns TRUE if the given row and column is valid.</td>
</TR>
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">BOOL IsValid(const CCellID& cell)</FONT></PRE>
</TD><TD WIDTH="50%">Returns TRUE if the given cell is valid.</td>
</TR>
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">BOOL IsValid(const CCellRange& range)</FONT></PRE>
</TD><TD WIDTH="50%">Returns TRUE if the given cell range is valid.</td>
</TR>
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">CCellID GetNextItem(CCellID& cell, int nFlags) const</FONT></PRE>
</TD><TD WIDTH="50%">Searches for a cell that has the specified properties and that bears the
specified relationship to a given item. (See also CListCtrl::GetNextItem and
<a href="gridctrl.shtml#CellSearch">Cell Searching options</a>)</td>
</TR>
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">BOOL SortTextItems(int nCol, BOOL bAscending)</FONT></PRE>
</TD><TD WIDTH="50%">Sorts the grid on the given column based on cell text.
Returns TRUE on success.</td>
</TR>
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">BOOL SortItems(PFNLVCOMPARE pfnCompare, int nCol,
BOOL bAscending, LPARAM data = 0)</FONT></PRE>
</TD><TD WIDTH="50%">Sorts the grid on the given column using the supplied
compare function pfnCompare. See CListCtrl::SortItems for information in the
form of this function. Returns TRUE on success.</td>
</TR>
</table>
<h3><a name="Printing">Printing</a></h3>
<TABLE CELLSPACING=0 WIDTH="90%">
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">void Print()</FONT></PRE>
</TD><TD WIDTH="50%">Prints the grid control on the user selected device.
(Useful where the control is used in a dialog)</td>
</TR>
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">virtual void OnBeginPrinting(CDC *pDC, CPrintInfo *pInfo)</FONT></PRE>
</TD><TD WIDTH="50%">Used in a Doc/View environment. Call in your CView dervied
class' OnBeginPrinting.</td>
</TR>
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">virtual void OnPrint(CDC *pDC, CPrintInfo *pInfo)</FONT></PRE>
</TD><TD WIDTH="50%">Used in a Doc/View environment. Call in your CView dervied
class' OnPrint.</td>
</TR>
<TR VALIGN=TOP><TD WIDTH="50%">
<PRE><FONT COLOR="#990000">virtual void OnEndPrinting(CDC *pDC, CPrintInfo *pInfo)</FONT></PRE>
</TD><TD WIDTH="50%">Used in a Doc/View environment. Call in your CView dervied
class' OnEndPrinting.</td>
</TR>
</table>
<h3><a name="Structures">Structures, defines and Messages</a></h3>
<p><a name="CCellID">The <b>CCellID</b> class<a>. This is a handy helper class used
to reference individual cells. All members are public. This class is
adapted from Joe Willcoxsons original implementation.
<PRE><FONT COLOR="#990000">class CCellID
{
public:
int row, col; // The zero based row and column of the cell.
CCellID(int nRow = -1, int nCol = -1)
int IsValid();
int operator==(const CCellID& rhs);
int operator!=(const CCellID& rhs);
}
</FONT></PRE>
<p><a name="CCellRange">The <b>CCellRange</b> class<a>. This is a handy helper class used
to reference cell ranges. This class is adapted from Joe Willcoxsons original
implementation.
<PRE><FONT COLOR="#990000">class CCellRange
{
public:
CCellRange(int nMinRow = -1, int nMinCol = -1, int nMaxRow = -1, int nMaxCol = -1);
void Set(int nMinRow = -1, int nMinCol = -1, int nMaxRow = -1, int nMaxCol = -1);
int IsValid() const;
int InRange(int row, int col) const; // Is the row/col in the range?
int InRange(const CCellID& cellID) const; // is the cell in the range?
CCellID GetTopLeft() const; // Get topleft cell in range
CCellRange Intersect(const CCellRange& rhs) const;
// Returns the intersection of
// two cell ranges
int GetMinRow() const; // Self explanatory
void SetMinRow(int minRow);
int GetMinCol() const;
void SetMinCol(int minCol);
int GetMaxRow() const;
void SetMaxRow(int maxRow);
int GetMaxCol() const;
void SetMaxCol(int maxCol);
int GetRowSpan() const; // Number of rows spanned
int GetColSpan() const; // Number of columns spanned
int operator==(const CCellRange& rhs);
int operator!=(const CCellRange& rhs);
}
</FONT></PRE>
<p>
<a name="GV_ITEM">The GV_ITEM structure<a>. This structure is used for Get/SetItem calls.
<PRE><FONT COLOR="#990000">typedef struct _GV_ITEM {
int row,col; // Row and Column of item
UINT mask; // Mask for use in getting/setting cell data
UINT state; // cell state (focus/hilighted etc)
UINT nFormat; // Format of cell. Default imaplentation used CDC::DrawText formats
CString szText; // Text in cell
int iImage; // index of the list view item抯 icon
COLORREF crBkClr; // Background colour (or CLR_DEFAULT)
COLORREF crFgClr; // Forground colour (or CLR_DEFAULT)
LPARAM lParam; // 32-bit value to associate with item
LOGFONT lfFont; // cell font
} GV_ITEM;</FONT></PRE>
<a name="GVL_Values">Grid line selection</a>
<PRE><FONT COLOR="#990000">GVL_NONE - No grid lines
GVL_HORZ - Horizontal lines only
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -