Home page



Getting started


A grid control is a spreadsheet-like control that displays a series of rows and columns. Each cell is referenced by the position (row, column) in the grid.

Referencing cells

It can have columns headers and rows headers, also called fixed rows and fixed columns. Fixed rows are fixed when you scroll vertically. Fixed columns are fixed when you scroll horizontally.

In SCGrid, fixed cells are numbered negative so non-fixed cells always start with 0.

For example, the first column of the first fixed row is referenced as (Row,Col) = (-1,0) and the first non-fixed cell is always referenced as (0,0). Thus, when adding a fixed row or a fixed column, you dont need to recalculate the position of non-fixed cell.

Designing the grid

At design, you can quickly configured the appearance and the behavior of the grid. You can set the number of rows, columns, the background color, the line color, font, etc...

  • AdjustLast
  • BackColor
  • BackColorSel
  • BorderStyle
  • CaptionEnabled : FixedRows property must be set to at least 1.
  • Cols
  • DataMember
  • DataSource
  • DefaultBkColor
  • DefaultForeColor
  • DefaultHeight
  • DefaultLineColor
  • DefaultWidth
  • FixedCols
  • FixedRows
  • FocusRect
  • Font
  • ForeColorSel
  • GridLines
  • GridLineWidth
  • MaskColor : UseMask must be set to scMaskColor
  • Opacity : must be used with a background picture.
  • Picture
  • PictureMode
  • Redraw
  • ResizeMode
  • ResizingRows
  • Rows
  • ScrollBarSize
  • ScrollBarStyle
  • ScrollHBar
  • ScrollVBar
  • SelectMode
  • ShowSplit
  • UseMask
  • VirtualPageSize : will affect the number of rows.

Adding rows and columns

You can do this once at design or you can code in the Form_Load event:

	SCGrid1.Cols = 8 
	SCGrid1.Rows = 100 
	' coding in this order (Cols then Rows) is more efficient,
	' the display will be faster

If you dont know, in advance, the number of cols or rows then you must add one column or one row at a time (for example, when data is stored in a file):

	' assume you know the number of columns but not the number of rows
	i = 0 
	SCGrid1.Rows = 0 
	Do While GetDataFromFile (sData) 
		' a function which retrieves a record in sData 
		' and returns False if EOF 
		' in the first iteration, i = 0, you add one row 
		' but you insert at row zero (non-fixed cell starts at zero)  
		SCGrid1.Rows = i + 1 
		' or SCGrid1.InsertRows i 
		' populate row 
		SCGrid1.Text (i, 0) = sData.Name 
		SCGrid1.Text (i, 1) = sData.Address .... 
                i = i + 1
	Loop 
Another way (faster), is to assign a number of rows before populating the grid. The number will be the average maximum of records.
	' assume you know the number of columns but not the number of rows 
	i = 0 
	SCGrid1.Rows = 1000 
	Do While GetDataFromFile (sData) 
		' a function which retrieves a record in sData 
  		' and returns False if EOF 
		' in the first iteration, i = 0, you add one row 
		' but you insert at row zero (non-fixed cell starts at zero)  
		If SCGrid1.Rows = i Then SCGrid1.Rows = i + 1 
		' or If ... Then SCGrid1.InsertRows i 
		' or also If ... Then SCGrid1.Rows = SCGrid1.Rows + 100
		' populate row 
  		SCGrid1.Text (i, 0) = sData.Name 
		SCGrid1.Text (i, 1) = sData.Address .... 
		i = i + 1
	Loop
	SCGrid1.Rows = i 
	' adjust Rows with the number of records 
To add fixed cells, you must use FixedCols or FixedRows. The first fixed row (-1) and fixed column (-1) start at, respectively, the bottom and right.

Formatting grid

A cell can have its own :

  • background color
  • foreground color
  • border color
  • gradient mode
  • mode, the cell can be
    • a fixed cell (default).
    • a built-in check-box.
    • a built-in command button.
    • a built-in text-box
    • a built-in combo-box. User can type in the field.
    • a built-in combo-box. User can only choose in the list.
    • a custom control.
    • a built-in press button.
  • style, the cell will be drawn
    • without visual effects.
    • with sunken edge.
    • with raised edge.
    • as a button.
  • picture alignment, the picture can be
    • left-aligned (default).
    • centered.
    • right-aligned.
    • top-aligned.
    • centered vertically.
    • bottom-aligned.
    • resized to fit the cell.
  • text alignment
    • Text is left-aligned (default).
    • Text is centered.
    • Text is right-aligned.
    • Text is centered vertically. This value is used only with the scSingleLine value.
    • Text is bottom-aligned.
    • Displays text on a single line only. Carriage returns and line feeds do not break the line (by default, the text is displayed on multi-lines).
    • Breaks words. Lines are automatically broken between words if a word would extend past the edge of the cell. A carriage return-line feed sequence also breaks the line.
    • Truncates any word that does not fit in the cell and adds ellipses.
    • Draws a 3D check-box, if CellMode (ColMode or RowMode) is set to scCheckBox. Check-box is always centered.
    • Turns off processing of prefix characters. This is the default value. To accept underscore character, you must set the TextAlignment property to -scNoPrefix (the minus is important).
  • text right margin
  • text left margin
For picture and text alignment, you can combine more than one alignment (alignments must be compatible). For example:
 
    'Right-aligned' + 'bottom-aligned' is correct
    'Bottom-aligned' + 'resized to fit the cell' is not correct
    'Single line' + 'breaks words' is not correct

Performance Tips and Tricks

Set the Redraw property to False whenever you are doing a lot of cells formatting.

Add fixed cells before non-fixed cells. And add columns before rows.

For example :

    With SCGrid1
    	.Redraw = False
	.FixedCols = 1
	.FixedRows = 2
	.Cols = 8
	.Rows = 1000
	' here the cells formatting
	.Redraw = True
    End With

Theoretically, SCGrid can have 32766 rows (including fixed rows) and the same limit for columns. But, performance can be unacceptable depending on the system resources.


.

Copyright 2001-2009 SCGrid.com