User Tools

Site Tools


17.7.2 Selected GridView Properties

These are the main grid properties that you can set or read:

GridView.HeaderThe property determines whether a header line is displayed or not (0=None) or in which orientation it is displayed: 3=Both, 1=Horizontal or 2=Vertical

Table: Description Grid property .Header.

The properties can apply to all columns or only to selected columns:

GridView.Columns.CountRW Number of columns in the GridView
GridView.Columns.WidthRW Width of all columns in pixels
GridView.Columns[k].WidthRW Width of column k in pixels
GridView.Columns.ResizableRW Resizable specifies with the value TRUE or FALSE whether all columns in the width can be changed or not and must be set before all other properties.
GridView.Columns[k].ResizableRW Resizable specifies with the value TRUE or FALSE whether the column width of column k can be changed or not and must be set after GridView.Columns.Count.
GridView.Columns.HeightRThe height of the header line in pixels is read

Table: Description of selected grid properties - columns

The same applies to the rows in the GridView:

GridView.Rows.CountRWNumber of grid rows. If the number is 0, no data grid is displayed.
GridView.Rows.WidthRHeight of the column header in pixels.
GridView.Rows[k].HeightRWHeight of line k.
GridView.Rows.ResizableRWResizable specifies with the value TRUE or FALSE whether the row height can be changed or not.
GridView.Rows.HeightRWHeight of all data rows in pixels.

Table: Description of selected grid properties - rows

The description of further properties of the GridView follows:

GridView.ColumnRW Sets or reads the current column
GridView.RowRW Sets or reads the current line
GridView.currentR Returns the properties of a cell; type GridViewCell: Alignment, BackColor, Background, Font, ForeColor, Foreground, Height, Left, Padding, Picture, RichText, Text, Top, Width, X, Y
GridView.GridW The values TRUE or FALSE determine whether grid lines are drawn or not.
GridView.ModeRW The selection mode for rows has 3 modes: Select.None, Select.Single and Select.Multiple. Only in the Select.Single and Select.Multiple modes are the selected rows highlighted in color, otherwise, for example, the column header in bold.
GridView[z,s].TextW Text in the cell[row,column]
GridView[z,s].AlignmentRW Text alignment in the cell[z,s] with 13 different values. Compare with the information in chapter 20.7 on the Align class.
GridView[z,s].PictureW You can also insert multimedia objects - for example an image - into a cell with Picture[“image.png”].
GridView.DataRWThe virtual class is only valid in connection with the GridView.Data event and has the following properties - Alignment, BackColor, Background, Font, ForeColor, Foreground, Padding, Picture, RichText and Text for the grid content.

Table: Description of selected grid properties

These two methods are of particular interest:

GridView.Clear()The data grid is deleted. For example, if GridView.Header = 1 a header line with column headers is displayed, it is retained.
GridView.MoveTo(z,s)Sets the current cell to row=z and column=s

Table: Description of selected methods

It has proved to be advantageous to set the grid properties in a separate procedure, as shown in the following excerpts from two different source texts. The number of columns is known in the first section:

PRIVATE SUB SetGridProperty() 
  GridView1.Resizable = TRUE  ' Muss vor allen anderen Eigenschaften gesetzt werden
  GridView1.Mode = Select.Single
  GridView1.Columns.Count = 4 
  GridView1.Header = GridView1.Both 
  GridView1.Columns[0].Width = 110 
  GridView1.Columns[0].Title = "Zahl" 
  GridView1.Columns[1].Width = 120 
  GridView1.Columns[1].Title = "Wahrheitswert" 
END ' SetGridProperty()

In the second source code excerpt, the number of columns is determined and the column headers are generated dynamically:

PUBLIC SUB SetGridViewProperty() 
  DIM iDatensatzNummer, iSpaltenNummer AS Integer   
GridView.Header = 1 ' GridView.Horizontal
  GridView.Columns.Count = rDBResult.Fields.Count 
  GridView.Columns[0].Width = 25 
  GridView.Columns[0].Resizable = FALSE ' Nur diese Feldbreite ist fix
' GridView-Spalten-Bezeichner ermitteln und eintragen 
  FOR iSpaltenNummer = 0 TO rDBResult.Fields.Count - 1 
      GridView.Columns[iSpaltenNummer].Title = rDBResult.Fields[iSpaltenNummer].Name 
  NEXT ' Feldname 
END ' SetGridViewProperty

The following sections describe projects that use a GridView to display data from different sources and offer various options for inserting the data:

  • GridView with fixed number of columns; insertion of data without buffering
  • Display of data from a database table, where the number of rows and columns - depending on the SQL query - is not known at program start.
  • Export data from a GridView to a csv file.
  • Data import from a csv file and display the data in a GridView.

The next two projects only make sense if you can save the manipulated data in the grid view, for example, in a csv file or read it in again:

  • Change of contents of selected cells in a GridView,
  • Change selected cells in a GridView using a special class.

The final project requires Gambas 3 - at least in revision 4715:

  • Sorting of data in a GridView

The source code is only fully specified and explained for those procedures and functions that are necessary for understanding the properties and methods used in GridView.


The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k17/k17.7/k17.7.2/start.txt · Last modified: 30.09.2023 by emma

Page Tools