Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Objective Grid User's Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

18.3 The BrwsGrid Program

This section examines the BrwsGrid program you just ran. The grid in this program displays and allows you to edit the data stored in the data member m_data of the document.

In the following sections, code modules are followed by the explanations of the comments.

18.3.1 Initialization and Setting Column Count

//1

Initializes the default browser settings.

//2

Set the column count in the grid based on the number of columns in your external data source. This allows you to set the base styles for the columns in the following lines.

//3

The following lines change the column base style in the corresponding columns, thereby affecting all the cells in those columns. Note that the browser grid does not allow you to set the styles for individual cells.

//4

Initialize the column names here.

18.3.2 Supplying the Row Count Dynamically

//1

Supply the row count from your external data source here. This function will be called every time the grid has to be redrawn.

18.3.3 Managing Sorted Rows and Moved Columns

//1

The browser grid enables moving columns by maintaining a map which translates the current moved column position into the original column before moving. This function converts the current column to the corresponding field in your data source. If your data source has columns that are zero-based, then you should make this function return the appropriate field number.

//2

The above discussion holds true for sorted rows as well.

18.3.4 Supplying the Value To the Grid and Storing the Changes

//1

Translate the column number to the field count in your data source.

//2

If pszExistingValue == NULL, then the grid already has the value in its internal buffer and you should only supply specific formatting here.

//3

If m_bNoValueNeeded == TRUE, then you do not have to supply the value here. This flag will be set while composing styles for tooltips which do not require the value.

//4

Get the value from your data source and set it in the composed style.

//5

This function will be called when the user edits one or more fields in a row and moved to another row and for each edited field in that row. Store the change back into your data source in this function.

//6

nField is greater than the field count if you had unbound columns in your grid. If that is the case, make sure that the unbound column is disabled. (This is usually the case.)

//7

Store the value back into your data source.

18.3.5 Deleting Rows

Override DeleteRows(), as shown in the tutorial sample code. The code is not discussed here line by line, since it is very elaborate. Please refer to the source code in the sample project for detailed information.

Basically, this code deals with the issue of deleting multiple non-contiguous rows. The problem is that as soon as you delete a row, the index of any row that is to be deleted (and that is below the current deleted row) becomes invalid.

It resolves the issue by deleting rows one at a time from bottom up, so that all the indexes for the rows to be deleted remain valid.

It also updates the internal data structure that is a map of the current moved rows to their original position before they were moved.



Previous fileTop of DocumentContentsNo linkNext file

Copyright © Rogue Wave Software, Inc. All Rights Reserved.

The Rogue Wave name and logo, and Stingray, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.