sheetwnd.gif (8503 bytes)A CSheetWnd object is an MFC-based window (compatible with Visual C++ version 5 and later) that contains a grid-like sheet of string data elements. Users can select, insert, delete, and move up and down rows, and edit individual cells in the sheet. Changes effected by user are communicated to the parent window through WM_NOTIFY messages. The window also supports the resizing of columns in the style if Windows 95 list view controls. Editable fields may also be combo boxes. Additional display features include a column header with tooltips, scrolling, and the freezing of the first column when the window is scrolled horizontally.

 

This page contains the documentation of CSheetWnd. For purchase information, please skip to the bottom of the page.

 

Users can interact with the control by selecting rows, editing cells in the sheet, or using a context menu (invoked through the right mouse button) for moving rows up and down, or inserting and deleting rows. Whenever the user changes the contents of the window, the parent window receives notification through a WM_NOTIFY message.

 

The window supports the following notification codes:

 

SHN_MOVEUP Indicates that a row has been moved up.
SHN_MOVEDOWN Indicates that a row has been moved up.
SHN_INSERT Indicates that a new row has been inserted.
SHN_DELETE Indicates that an existing row has been deleted.
SHN_EDIT Indicates that a row’s content has been edited.
SHN_OPEN Called to check if a particular cell is editable.
SHN_GETCBSTRING Called to obtain a text string for a combo box.
SHN_TOOLTIPTEXT Called to obtain a text string for a tooltip.

 

All notification messages set the wParam parameter to point to the following structure:

 

typedef struct tagSHN {
	NMHDR hdr;
	int nRow;
	int nCol;
	int nItem;
	HINSTANCE hinst;
	LPTSTR lpszText;
} SHN;

 

The nRow and nCol parameter specifies the cell that has been affected by the user’s action. Note that in case of SHN_MOVEUP and SHN_MOVEDOWN notifications, nRow identifies the index of the affected row prior to the move.

 

The nItem parameter is used for combo boxes. It contains the index of the combo box item requested.

 

The hinst and lpszText parameters are used for tooltip texts. The application should fill these with the instance handle and resource identifier of the text to be used for the tooltip. If pointer to a string is used instead, the instance handle should be zero. The string should be allocated on the heap and it is freed by the function.

 

CSheetWnd Class Members

 

Data Members

m_nCols The number of columns in the sheet. Never modify this member directly.
m_nRows The number of rows in the sheet. Never modify this member directly.
m_nSelRow The zero-based index of the currently selected row. It is not recommended to modify this member directly, as the modification will not be reflected in the window unless you force a repaint.
m_nSelCol The zero-based index of the currently selected column. It is not recommended to modify this member directly, as the modification will not be reflected in the window unless you force a repaint.

Construction

CSheetWnd Constructs a CSheetWnd object.

Attributes

CanMoveUp Determines if a row can be moved up.
CanMoveDown Determines if a row can be moved down.

Operations

AddCol Adds a column.
AddRow Adds a row.
DeleteRow Deletes a row.
GetValue Retrieves the string value of a cell in the sheet.
InsertRow Inserts a row.
MoveUp Moves a row upward.
MoveDown Moves a row downward.
Reset Resets the contents of the object.
SetValue Sets the string value of a cell in the sheet.

 


 

CSheetWnd()

 

Remarks
Constructs a CSheetWnd object. After the object has been constructed, use CWnd::Create to create a sheet window.

 


 

BOOL CanMoveUp(int nRow)

 

Return Value
Nonzero if the specified row can be moved upwards.

 

Parameters  
nRow The index of the row to be queried.

 

Remarks
Call this member function to determine if a row can be moved upwards. A row can be moved upwards if the following conditions are true:
  • The row is not the first row in the sheet;
  • The row has the SH_MOVABLE flag;
  • The row immediately preceding the specified row also has the SH_MOVABLE flag.

 


 

BOOL CanMoveDown(int nRow)

 

Return Value
Nonzero if the specified row can be moved downwards.

 

Parameters  
nRow The index of the row to be queried.

 

Remarks
Call this member function to determine if a row can be moved downwards. A row can be moved downwards if the following conditions are true:
  • The row is not the last row in the sheet;
  • The row has the SH_MOVABLE flag;
  • The row immediately following the specified row also has the SH_MOVABLE flag.

 


 

BOOL AddCol(DWORD dwFlags, int nWidth, const CString &strLabel)

 

Return Value
Nonzero if successful.

 

Parameters  
dwFlags Flags that specify the column’s behavior. For allowable values, see the Remarks section.
nWidth The width of the column, in pixels.
strLabel The title of the column.

 

Remarks
Call this member function to add a column to the window. Note that columns can only be added in sequence; no facilities exist for swapping or inserting columns.

The column’s behavior is controlled by the dwFlags parameter. This parameter can be a combination of the following values:
SH_EDITABLE Indicates that values in this column can be edited, unless they are in SH_SUMMARY rows
SH_RIGHTALIGN Print the column’s header and contents right aligned
SH_COMBOBOX Indicates that when edited, the field is to appear as a combo box instead of an edit control.

 

Note that a WM_NOTIFY message will not be sent to the parent window. WM_NOTIFY messages are sent only for actions initiated by the user.

 


 

BOOL AddRow(DWORD dwFlags)

 

Return Value
Nonzero if successful.

 

Parameters  
dwFlags Flags that specify the row’s behavior. For allowable values, see the Remarks section.

 

Remarks
Call this member function to add a row to the window. The row will be added after the last row in the window.

The row’s behavior is controlled by the dwFlags parameter. This parameter can be a combination of the following values:
SH_SUMMARY Indicates that the contents of the row are calculated and cannot be edited, even if there are columns marked SH_EDITABLE.
SH_OVERRIDE Indicates that the contents of the row represent override values and should be displayed using a different color.
SH_INSERTABLE Indicates that rows can be inserted before this row.
SH_DELETABLE Indicates that the row can be deleted.
SH_MOVABLE Indicates that the row can be moved up or down. Note that in order for a row to be movable, the row immediately preceding (or succeeding) it must also be marked movable.
SH_DONTEDITFIRSTCOL Indicates that the first column of the row shall not be edited. To be used typically in combination with the SH_SUMMARY or SH_OVERRIDE styles.

 

Note that a WM_NOTIFY message will not be sent to the parent window. WM_NOTIFY messages are sent only for actions initiated by the user.

 


 

BOOL DeleteRow(int nRow)

 

Return Value
Nonzero if successful.

 

Parameters  
nRow The index of the row that is to be deleted.

 

Remarks
Call this member function to delete a row. The row’s contents will be discarded.

Note that a WM_NOTIFY message will not be sent to the parent window. WM_NOTIFY messages are sent only for actions initiated by the user.

 


 

BOOL GetValue(int nRow, int nCol, CString &strValue)

 

Return Value
Nonzero if successful.

 

Parameters  
nRow The row number of the cell to be updated.
nCol The column number of the cell to be updated.
strValue A CString object that will hold the retrieved value.

 

Remarks
Call this member function to retrieve the value of a cell.

 


 

BOOL InsertRow(int nRow, DWORD dwFlags)

 

Return Value
Nonzero if successful.

 

Parameters  
nRow The index that marks the row before which the new row is to be inserted.
dwFlags Flags that specify the row’s behavior. For allowable values, see the Remarks section.

 

Remarks
Call this member function to add a row to the window. The row will be added after the last row in the window.

The row’s behavior is controlled by the dwFlags parameter. For allowable values, see the documentation of the CSheetWnd::AddRow member function.

Note that a WM_NOTIFY message will not be sent to the parent window. WM_NOTIFY messages are sent only for actions initiated by the user.

 


 

BOOL MoveUp(int nRow)

 

Return Value
Nonzero if successful.

 

Parameters  
nRow The index of the row that is to be moved.

 

Remarks
Call this member function to move a row upwards. To determine whether a row can be moved upwards, see the documentation of the CSheetWnd::CanMoveUp member function.

Note that a WM_NOTIFY message will not be sent to the parent window. WM_NOTIFY messages are sent only for actions initiated by the user.

 


 

BOOL MoveDown(int nRow)

 

Return Value
Nonzero if successful.

 

Parameters  
nRow The index of the row that is to be moved.

 

Remarks
Call this member function to move a row downwards. To determine whether a row can be moved downwards, see the documentation of the CSheetWnd::CanMoveDown member function.

Note that a WM_NOTIFY message will not be sent to the parent window. WM_NOTIFY messages are sent only for actions initiated by the user.

 


 

BOOL Reset()

 

Return Value
Nonzero if successful.

 

Remarks
Call this member function to reset the contents of the window. All rows and columns will be deleted.

Note that a WM_NOTIFY message will not be sent to the parent window. WM_NOTIFY messages are sent only for actions initiated by the user.

 


 

BOOL SetValue(int nRow, int nCol, const CString &strValue)

 

Return Value
Nonzero if successful.

 

Parameters  
nRow The row number of the cell to be updated.
nCol The column number of the cell to be updated.
strValue The new value of the cell.

 

Remarks
Call this member function to change the value of a cell. The cell’s old value will be discarded.

Note that a WM_NOTIFY message will not be sent to the parent window. WM_NOTIFY messages are sent only for actions initiated by the user.

 


 

A license to use the CSheetWnd class in your application can be purchased online here. When you place an order, a copy of the CSheetWnd DLL, header and library files, and sample code will be e-mailed to you, usually within 24 hours. If you purchase an unrestricted license, you will also receive a copy of the CSheetWnd source code.

 

License type

Price in USD

Buy Now!
Single Developer License
Authorizes a single developer to use the library in his or her projects, and redistribute the DLL to end-users. No source code is included.
$50.00

Site License
Authorizes a group of developers working together at the same geographic location to use the library in their projects, and redistribute the DLL to end-users. No source code is incldued.
$250.00

Unrestricted License
Provides a non-exclusive license to do as you please with the library. Includes the license to modify the library, redistribute the library in source or object form, or incorporate the library or any parts thereof into your projects. Source code included.
$1500.00