These are the main grid properties that you can set or read:
Property | Description |
---|---|
GridView.Header | The 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: 17.7.2.1 Description Grid property .Header.
The properties can apply to all columns or only to selected columns:
Property | Read/Write | Description |
---|---|---|
GridView.Columns.Count | RW | Number of columns in the GridView |
GridView.Columns.Width | RW | Width of all columns in pixels |
GridView.Columns[k].Width | RW | Width of column k in pixels |
GridView.Columns.Resizable | RW | 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].Resizable | RW | 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.Height | R | The height of the header line in pixels is read |
Table: 17.7.2.2 Description of selected grid properties - columns
The same applies to the rows in the GridView:
Property | Read/Write | Description |
---|---|---|
GridView.Rows.Count | RW | Number of grid rows. If the number is 0, no data grid is displayed. |
GridView.Rows.Width | R | Height of the column header in pixels. |
GridView.Rows[k].Height | RW | Height of line k. |
GridView.Rows.Resizable | RW | Resizable specifies with the value TRUE or FALSE whether the row height can be changed or not. |
GridView.Rows.Height | RW | Height of all data rows in pixels. |
Table: 17.7.2.3 Description of selected grid properties - rows
The description of further properties of the GridView follows:
Property | Read/Write | Description |
---|---|---|
GridView.Column | RW | Sets or reads the current column |
GridView.Row | RW | Sets or reads the current line |
GridView.current | R | 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.Grid | W | The values TRUE or FALSE determine whether grid lines are drawn or not. |
GridView.Mode | RW | 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].Text | W | Text in the cell[row,column] |
GridView[z,s].Alignment | RW | 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].Picture | W | You can also insert multimedia objects - for example an image - into a cell with Picture[“image.png”]. |
GridView.Data | RW | The 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: 17.7.2.4 Description of selected grid properties
These two methods are of particular interest:
Method | Description |
---|---|
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: 17.7.2.5 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:
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:
The final project requires Gambas 3 - at least in revision 4715:
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.