GridWidget

Object Hierarchy | Related C++ Class: GridWidget

Introduced

v4.2

Description

The GridWidget object represents the user interface control that shows a GridData object inside a Property Page. It exposes information that is transitive and directly related to the state of the control itself rather than the underlying GridData. For example, this object exposes information about which cells the user has clicked on.

Unlike the actual GridData content, the selection state is lost when the Property Page (PPG) is closed and then reopened.

Note: The layout of the GridData on the property page is defined by the PPGItem object that represents the GridData on the PPGLayout for that property page. For example, the siUIGridSelectionMode attribute controls whether cells are selected individually, by row or column, or not at all (see siPPGItemAttribute).

Methods

AddToSelection ClearSelection IsCellSelected IsColumnSelected
IsRowSelected SortColumn    
       

Examples

JScript Example

/*
	This example demontrates a typical use of the 
	GridWidget object - as a way of allowing users to 
	delete rows or columns from a GridData object
*/
var oProp = ActiveSceneRoot.AddProperty( "CustomProperty", 
				false, "GridWidgetDemo" );			
var oParameter = oProp.AddGridParameter( "DemoGrid" ) ;
var oGridData = oParameter.Value ;
oGridData.ColumnCount = 3
oGridData.RowCount = 20
// Fill in some initial values
for ( i = 0 ; i < oGridData.RowCount ; i++ )
	for ( j = 0 ; j < oGridData.ColumnCount ; j++ )
		oGridData.SetCell( j, i, i + "." + j ) ;
var oPPGLayout = oProp.PPGLayout
var oGridPPGItem = oPPGLayout.AddItem( "DemoGrid" )
oGridPPGItem.SetAttribute( siUINoLabel, true );
oGridPPGItem.SetAttribute( siUIGridSelectionMode, siSelectionHeader );
oGridPPGItem.SetAttribute( siUIGridColumnWidths, "25:100:75:100" );
oGridPPGItem.SetAttribute( siUIGridReadOnlyColumns, "1" );
oPPGLayout.AddRow() ;
oPPGLayout.AddButton( "DeleteRow", "Delete Selected Row(s)" ) ;
oPPGLayout.AddButton( "DeleteColumn", "Delete Selected Column(s)" ) ;
oPPGLayout.EndRow() ;
oPPGLayout.Language = "JScript" ;
oPPGLayout.Logic = DeleteRow_OnClicked.toString() + 
	DeleteColumn_OnClicked.toString() ; 
InspectObj( oProp ) ;
function DeleteRow_OnClicked()
{
	var oGridData = PPG.DemoGrid.Value ;
	oGridData.BeginEdit() ;
	var oGridWidget = oGridData.GridWidget
	// shift the rows upwards to overwrite the selected rows
	var writePos = 0 ;
	for ( var readPos = 0  ; readPos < oGridData.RowCount ; readPos++ )
	{
		if ( !oGridWidget.IsRowSelected(readPos) )
		{
			if ( readPos != writePos )
			{
				oGridData.SetRowValues( 
							writePos, 
							oGridData.GetRowValues( readPos ) ) ;
			}
			writePos++ ;
		}
	}
	// Shrink the GridData
	oGridData.RowCount = writePos ;
	oGridData.EndEdit() ;	
}
function DeleteColumn_OnClicked()
{
	var oGridData = PPG.DemoGrid.Value ;
	oGridData.BeginEdit() ;
	var oGridWidget = oGridData.GridWidget
	// shift the rows upwards to overwrite the selected rows
	var writePos = 0 ;
	for ( var readPos = 0  ; readPos < oGridData.ColumnCount ; readPos++ )
	{
		if ( !oGridWidget.IsColumnSelected(readPos) )
		{
			if ( readPos != writePos )
			{
				oGridData.SetColumnValues( 
							writePos, 
							oGridData.GetColumnValues( readPos ) ) ;
			}
			writePos++ ;
		}
	}
	// Shrink the GridData
	oGridData.ColumnCount = writePos ;
	oGridData.EndEdit() ;	
}

See Also

GridData GridData.GridWidget PPG siPPGItemAttribute