Core Function GUIDataGrid

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
(Created page with "<pre> GUIDataGrid( <datagrid> ) </pre> === Description === Properties & Functions specifically for Data Grid === Parameters === ==== datagrid ==== The DataGrid GUI object to...")
 
m (1 revision)
 
(8 intermediate revisions by one user not shown)
Line 5: Line 5:
 
=== Description ===
 
=== Description ===
  
Properties & Functions specifically for Data Grid
+
Properties & Functions specifically for DataGrid
  
 
=== Parameters ===
 
=== Parameters ===
Line 14: Line 14:
  
 
=== Functions ===
 
=== Functions ===
 +
 +
==== GetSelectedCells ====
 +
 +
Return array of all cells selected by user
 +
 +
Allow all one type
 +
<syntaxhighlight lang="sputnik">
 +
HotKeySet('{F1}', 'ShowSelectedCells($arg);');
 +
// Triggered by hotkey F1 this will print the cell locations that are selected
 +
Function ShowSelectedCells($arg)
 +
{
 +
$SelectedCells = GUIDataGrid($GS, "GetSelectedCells");
 +
if($SelectedCells)
 +
{
 +
println("Selected Cells Below");
 +
foreach($SelectedCells as $cell)
 +
{
 +
List( $ColumnID, $RowID ) = $cell;
 +
println("User has selected cell at ColumnID ' $ColumnID' RowID '$RowID'");
 +
}
 +
println("Selected Cells Above");
 +
}
 +
else
 +
{
 +
println("No Cells are selected");
 +
}
 +
}
 +
</syntaxhighlight>
 +
 +
==== GetSelectedColumns ====
 +
 +
Return array of all columns selected by user
 +
 +
Allow all one type
 +
<syntaxhighlight lang="sputnik">
 +
HotKeySet('{F2}', 'ShowSelectedColumns($arg);');
 +
// Triggered by hotkey F2 this will print the columns that are selected
 +
Function ShowSelectedColumns($arg)
 +
{
 +
$SelectedColumns = GUIDataGrid($GS, "GetSelectedColumns");
 +
if($SelectedColumns)
 +
{
 +
println("Selected Columns Below");
 +
foreach($SelectedColumns as $ColumnID)
 +
{
 +
println("User has selected ColumnID '$ColumnID'");
 +
}
 +
println("Selected Columns Above");
 +
}
 +
else
 +
{
 +
println("No Columns are selected");
 +
}
 +
}
 +
</syntaxhighlight>
 +
 +
==== GetSelectedRows ====
 +
 +
Return array of all rows selected by user
 +
 +
Allow all one type
 +
<syntaxhighlight lang="sputnik">
 +
HotKeySet('{F3}', 'ShowSelectedRows($arg);');
 +
// Triggered by hotkey F3 this will print the rows that are selected
 +
Function ShowSelectedRows($arg)
 +
{
 +
$SelectedRows = GUIDataGrid($GS, "GetSelectedRows");
 +
if($SelectedRows)
 +
{
 +
println("Selected Rows Below");
 +
foreach($SelectedRows as $RowID)
 +
{
 +
println("User has selected RowID '$RowID'");
 +
}
 +
println("Selected Rows Above");
 +
}
 +
else
 +
{
 +
println("No Rows are selected");
 +
}
 +
}
 +
</syntaxhighlight>
 +
 +
==== SelectionMode ====
 +
 +
Change the selection mode
 +
 +
Allow all one type
 +
<syntaxhighlight lang="sputnik">
 +
GUIDataGrid($GS, "SelectionMode", @CellSelect);
 +
</syntaxhighlight>
 +
 +
Allow all two types
 +
<syntaxhighlight lang="sputnik">
 +
GUIDataGrid($GS, "SelectionMode", @CellSelect | @RowHeaderSelect);
 +
</syntaxhighlight>
 +
 +
Allow all types
 +
<syntaxhighlight lang="sputnik">
 +
GUIDataGrid($GS, "SelectionMode",
 +
@CellSelect |
 +
@FullColumnSelect |
 +
@FullRowSelect |
 +
@RowHeaderSelect |
 +
@ColumnHeaderSelect);
 +
</syntaxhighlight>
 +
 +
Possible types are:
 +
<pre>
 +
@CellSelect
 +
@FullColumnSelect
 +
@FullRowSelect
 +
@RowHeaderSelect
 +
@ColumnHeaderSelect
 +
</pre>
  
 
==== GetValue ====
 
==== GetValue ====
Line 162: Line 277:
 
=== Example ===
 
=== Example ===
  
<syntaxhighlight lang="sputnik">
+
Go see [[Core Function GUICreateDataGrid|GUICreate( "DataGrid" )]] for example.
// Create the GUI
+
$GUI = GUICreate("Window","DataGrid Test", 640, 480, -1, -1, 1); // Create a fixed dialog
+
$hWnd = GUIGetProp($GUI, "Handle"); // GUIs hWnd for use with Win__() functions if needed
+
//WinMove($hWnd, "", 0, 0); // Uncomment for example of using Win__() functions on a GUI window
+
GUILoad( $GUI ); // Show the GUI
+
+
// Create the DataGrid
+
$GS = GUICreate("DataGrid", $GUI, 8, 8, 610, 430);
+
$hWndGS = GUIGetProp($GS, "Handle"); // GUIs hWnd for use with Control__() functions if needed
+
//ControlHide($hWnd, "", $hWndGS); // Uncomment for example of using Control__() functions on a GUI object
+
+
//GUISetProp($GS, "AllowUserToDeleteRows", 0); // Uncomment to disallow deleting rows
+
//GUISetProp($GS, "AllowUserToAddRows", 0); // Uncomment to disallow adding rows
+
//GUISetProp($GS, "AllowUserToResizeRows", 0); // Uncomment to disallow resize rows
+
//GUISetProp($GS, "AllowUserToResizeColumns", 0); // Uncomemnt to disallow resize colums
+
//GUISetProp($GS, "AllowUserToOrderColumns", 0); // Uncomment to disallow order columns
+
+
// Set the colums for the Grid
+
GUIDataGrid($GS, "SetColumns", array("One", "Two", "Three"));
+
+
// Add some rows to it
+
GUIDataGrid($GS, "AddRow", array(1, 2, 3));
+
GUIDataGrid($GS, "AddRow", array(4, 5, 6));
+
GUIDataGrid($GS, "AddRow", array(7, 8, 9));
+
GUIDataGrid($GS, "AddRow", array("ABC", "XYZ", "OMG"));
+
GUIDataGrid($GS, "InsertRow", 4, array("ONE", "TWO", "THREE"));
+
 
+
//GUIDataGrid($GS, "Clear");// Uncomment to delete all data in the Data Grid
+
//GUIDataGrid($GS, "DelColumn", "Two"); // Uncomment to delete column "Two"
+
//GUIDataGrid($GS, "DelColumnAt", 0); // Uncomment to delete column at index 0
+
//GUIDataGrid($GS, "DelRow", 0); // Uncomment to delete row at index 0
+
//GUIDataGrid($GS, "AddColumn", "Four"); // Uncomment to add a another column
+
//GUIDataGrid($GS, "InsertColumn", 0, "Zero"); // Uncomment to insert a another column at index 0
+
+
// Get the colum and row count
+
$ColumnCount = GUIDataGrid($GS, "Columns"); // Get column count
+
$RowCount = GUIDataGrid($GS, "Rows"); // Get row count
+
$Columns = GUIDataGrid($GS, "GetColumns"); // Get array of all columns
+
+
// Print the count
+
println("Columns '$ColumnCount' Rows '$RowCount'");
+
+
// Loop through all rows and colums and print their values
+
$k = 0;
+
For($j = 0; $j < $RowCount; $j++)
+
{
+
For($i = 0; $i < $ColumnCount; $i++)
+
{
+
$Data = GUIDataGrid($GS, "GetValue", $i, $j);
+
//GUIDataGrid($GS, "SetValue", $i, $j, "Meows $i, $j"); // Uncomment to replace data at this position
+
println("Col '$Columns[$i]' ROW '$j' DATA '$Data'");
+
$k++;
+
}
+
}
+
+
// Assign some links
+
GUILink($GS, "DeletedRow", 'UserDeleted();');
+
GUILink($GS, "DeletingRow", 'UserDeleting();');
+
GUILink($GS, "CellBeginEdit", 'CellBeginEdit();');
+
GUILink($GS, "CellEndEdit", 'CellEndEdit();');
+
+
// Keep the GUI running as long as the window is open
+
While ( GUIStatus( $GUI ) ) DoEvents( );
+
+
// Triggers when user begins editing a cell (You have the option to cancel)
+
Function CellBeginEdit( )
+
{
+
println("User begin edit cell '$arg[0]' '$arg[1]'");
+
//return 1; // Uncomment this to disallow the user to edit this cell
+
}
+
+
// Triggers when user finishes editing a cell
+
Function CellEndEdit( )
+
{
+
println("User end edit cell '$arg[0]' '$arg[1]'");
+
}
+
+
// Triggers when user is deleting a row (You have the option to cancel)
+
Function UserDeleting( )
+
{
+
println("User is deleting the row '$arg'");
+
//return 1; // Uncomment this to cancel the users delete
+
}
+
+
// Triggers when user has deleted a row
+
Function UserDeleted( )
+
{
+
println("User deleted a row");
+
}
+
</syntaxhighlight>
+
  
 
[[Category:Core Function]]
 
[[Category:Core Function]]

Latest revision as of 12:37, 14 June 2015

GUIDataGrid( <datagrid> )

Contents

Description

Properties & Functions specifically for DataGrid

Parameters

datagrid

The DataGrid GUI object to use.

Functions

GetSelectedCells

Return array of all cells selected by user

Allow all one type

HotKeySet('{F1}', 'ShowSelectedCells($arg);');
// Triggered by hotkey F1 this will print the cell locations that are selected
Function ShowSelectedCells($arg)
{
	$SelectedCells = GUIDataGrid($GS, "GetSelectedCells");
	if($SelectedCells)
	{
		println("Selected Cells Below");
		foreach($SelectedCells as $cell)
		{
			List( $ColumnID, $RowID ) = $cell;
			println("User has selected cell at ColumnID ' $ColumnID' RowID '$RowID'");
		}
		println("Selected Cells Above");
	}
	else
	{
		println("No Cells are selected");
	}
}

GetSelectedColumns

Return array of all columns selected by user

Allow all one type

HotKeySet('{F2}', 'ShowSelectedColumns($arg);');
// Triggered by hotkey F2 this will print the columns that are selected
Function ShowSelectedColumns($arg)
{
	$SelectedColumns = GUIDataGrid($GS, "GetSelectedColumns");
	if($SelectedColumns)
	{
		println("Selected Columns Below");
		foreach($SelectedColumns as $ColumnID)
		{
			println("User has selected ColumnID '$ColumnID'");
		}
		println("Selected Columns Above");
	}
	else
	{
		println("No Columns are selected");
	}
}

GetSelectedRows

Return array of all rows selected by user

Allow all one type

HotKeySet('{F3}', 'ShowSelectedRows($arg);');
// Triggered by hotkey F3 this will print the rows that are selected
Function ShowSelectedRows($arg)
{
	$SelectedRows = GUIDataGrid($GS, "GetSelectedRows");
	if($SelectedRows)
	{
		println("Selected Rows Below");
		foreach($SelectedRows as $RowID)
		{
			println("User has selected RowID '$RowID'");
		}
		println("Selected Rows Above");
	}
	else
	{
		println("No Rows are selected");
	}
}

SelectionMode

Change the selection mode

Allow all one type

GUIDataGrid($GS, "SelectionMode", @CellSelect);

Allow all two types

GUIDataGrid($GS, "SelectionMode", @CellSelect | @RowHeaderSelect);

Allow all types

GUIDataGrid($GS, 	"SelectionMode", 
			@CellSelect | 
			@FullColumnSelect | 
			@FullRowSelect | 
			@RowHeaderSelect | 
			@ColumnHeaderSelect);

Possible types are:

@CellSelect
@FullColumnSelect
@FullRowSelect
@RowHeaderSelect
@ColumnHeaderSelect

GetValue

Get a value at a given Column, Row

$k = 0;
For($j = 0; $j < $RowCount; $j++)
{
	For($i = 0; $i < $ColumnCount; $i++)
	{
		$Data = GUIDataGrid($GS, "GetValue", $i, $j);
		println("Col '$i' ROW '$j' DATA '$Data'");
		$k++;
	}
}

SetValue

Set a value at a given Column, Row

$k = 0;
For($j = 0; $j < $RowCount; $j++)
{
	For($i = 0; $i < $ColumnCount; $i++)
	{
		GUIDataGrid($GS, "SetValue", $i, $j, "Meows $i, $j"); 
		$k++;
	}
}

Clear

Delete all rows and columns

GUIDataGrid($GS, "Clear");

AddColumn

Add a column to the end

GUIDataGrid($GS, "AddColumn", "Four");

InsertColumn

Add a column at a given location

GUIDataGrid($GS, "InsertColumn", 0, "Zero");

DelColumn

Delete a column by name

GUIDataGrid($GS, "DelColumn", "Two");

DelColumnAt

Delete a column at a given location

GUIDataGrid($GS, "DelColumnAt", 0);

ClearColumns

Delete all columns

GUIDataGrid($GS, "ClearColumns");

GetColumns

Get array of all Column names

$Columns = GUIDataGrid($GS, "GetColumns");

Columns

Get Column count

$ColumnCount = GUIDataGrid($GS, "Columns");

SetColumns

Set the columns to all names in array

GUIDataGrid($GS, "SetColumns", array("One", "Two", "Three"));

AddRow

Add a Row to the end (Array UBound must be equal to number of columns)

GUIDataGrid($GS, "AddRow", array(1, 2, 3));

InsertRow

Insert a Row at a given location (Array UBound must be equal to number of columns)

GUIDataGrid($GS, "InsertRow", 4, array("ONE", "TWO", "THREE"));

DelRow

Delete a given Row at a given location

GUIDataGrid($GS, "DelRow", 0);

ClearRows

Delete all rows

GUIDataGrid($GS, "ClearRows");

Rows

Get Row count

$RowCount = GUIDataGrid($GS, "Rows");

Example

Go see GUICreate( "DataGrid" ) for example.

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox