From Clomosy Docs
function AddNewProGrid(AComponent: TCLComponent; xName: string): TclProGrid;
AComponent : Specifies the parent of the object to be defined.
xName : The name of the defined grid should be written.
TclProGrid represents a grid control designed to simplify the processing of strings and related objects. It offers a structure that provides more design flexibility than the standard StringGrid. TclProGrid allows customization of the grid's appearance with flexible styling and theming options. Additionally, it can seamlessly handle large datasets by integrating with databases and supporting various data sources like JSON. It also supports user interaction with event management features, such as cell editing and selection modes.
Refer to the TclStringGrid page for standard grid usage.
Feature | Use of | Definition |
---|---|---|
TclProGrid | ProGrid1:TCLProGrid; | A variable belonging to the TclProGrid class is created. |
AddNewProGrid | ProGrid1 = Form1.AddNewProGrid(mainVertSB,'ClProGrid2'); | A new proGrid is added to the form. |
BeginUpdate - EndUpdate | ProGrid1.BeginUpdate; ProGrid1.EndUpdate; |
These methods are used to improve performance during the update of the grid component. They handle data or visual changes to the grid collectively, temporarily disabling user interactions between updates. BeginUpdate: Indicates the start of the grid component's update process. |
ColumnCount | ProGrid1.ColumnCount = 5; | Determines the number of columns of the grid. In the example, the number of columns is set to 5. |
RowCount | ProGrid1.RowCount = 10; | Determines the number of rows of the grid. In the example, the number of rows is set to 10. |
FixedColumns | ProGrid1.FixedColumns = 1; | Specifies the fixed number of column headings. |
FixedRows | ProGrid1.FixedRows = 1; | Specifies the fixed number of rows headings. |
Stretch | ProGrid1.Options.ColumnSize.Stretch = True; | Controls whether the widths of the columns within the grid are adjusted to fit the total width of the grid. When set to True, the columns automatically expand to fit the grid's width, regardless of the grid's overall size. When set to False, the columns are adjusted based on their content or manually specified widths. |
StretchAll | ProGrid1.Options.ColumnSize.StretchAll = True; | Determines whether the width of the columns within the grid is automatically adjusted based on the grid's total width. If set to True, the columns expand to fill the entire grid. If set to False, the columns adjust based on their content, and the grid's total width is not fully utilized. |
Mode | ProGrid1.Options.Selection.Mode = smNone; | Sets the selection mode. smSingleColumn: Highlights the entire column of the selected cell. smSingleRow: Highlights the entire row of the selected cell. smNone: Does not change the color of the selected cell. |
Editing | ProGrid1.Options.Editing.Enabled = True; | Allows cells in the grid to be editable. This option enables users to directly edit the content of cells within the grid. When set to True, the cells become editable. If set to False, the cells are set to read-only. |
AutoSizeColumns | ProGrid1.AutoSizeColumns(True,300); | This method is used to automatically adjust the width of the header columns in the grid. When set to True, it automatically adjusts the width of all columns in the grid. When set to False, it only adjusts the width of the specified column. |
ClSenderRow | FRow = Form1.ClSenderRow; (FRow: Integer) | Returns the value of the clicked row in the grid. |
ClSenderCol | FCol = Form1.ClSenderCol; (FCol: Integer) | Returns the value of the clicked column in the grid. |
Cells | ProGrid1.Cells[Form1.clSenderCol,Form1.clSenderRow] = 'Value 1'; | It is used to get or set data in a specific cell. |
GetCellValue | ShowMessage(ProGrid1.GetCellValue(1,1)); | The function allows you to read data from a specific cell. |
FontSizes[Column,Row] | ProGrid1.FontSizes[2,3] = 15; | Determines the text size of the specified cell. |
FontStyles[Column,Row] | ProGrid1.FontStyles[2,3] = 0; | Specifies the style of the text in the given cell: 0: Standard 1: Bold 2: Italic 3: Italic, Bold 4: Underlined 5: Underlined, Bold 6: Underlined, Italic 7: Underlined, Bold, Italic 8: Strikethrough 9: Strikethrough, Bold 10: Strikethrough, Italic 11: Strikethrough, Italic, Bold 12: Strikethrough, Underlined 13: Strikethrough, Underlined, Bold 14: Strikethrough, Underlined, Italic 15: Strikethrough, Underlined, Italic, Bold |
FontNames[Column,Row] | ProGrid1.FontNames[2,5] = 'arial'; | Determines the font in the specified column and row. |
FontColors[Column,Row] | ProGrid1.FontColors[1,1] = clAlphaColor.clHexToColor('#da01bd'); | Determines the color of the text in the selected row and column cell. |
Colors[Column,Row] | ProGrid1.Colors[1,1] = clAlphaColor.clHexToColor('#da01bd'); | Determines the background color of the text in the selected row and column cell. |
RowHeights[Row] | ProGrid1.RowHeights[3] = 50; | Determines the row height. |
ColumnWidths[Column] | ProGrid1.ColumnWidths[4] = 200; | Determines the column width. |
HorzAlignments | ProGrid1.HorzAlignments[2,3] = 1; | Sets the horizontal alignment of the text in the cell. If not set, the default value is 0. (0: gtaCenter, 1: gtaLeading, 2: gtaTrailing) |
VertAlignments | ProGrid1.VertAlignments[3,4] = 2; | Sets the vertical alignment of the text in the cell. If not set, the default value is 0. (0: gtaCenter, 1: gtaLeading, 2: gtaTrailing) |
FixedLayoutFillColor | ProGrid1.FixedLayoutFillColor = clAlphaColor.clHexToColor('#de02ed'); | Specifies the background color of the header (fixed row/column). |
FixedLayoutFontColor | ProGrid1.FixedLayoutFontColor = clAlphaColor.clHexToColor('#de02ed'); | Specifies the text color of the header (fixed row/column). |
FocusedLayoutFillColor | ProGrid1.FocusedLayoutFillColor = clAlphaColor.clHexToColor('#02edde'); | Sets the background color of the selected row. |
FocusedLayoutFontColor | ProGrid1.FocusedLayoutFontColor = clAlphaColor.clHexToColor('#0c1d1b'); | Sets the text color of the selected row. |
SelectedLayoutFillColor | ProGrid1.SelectedLayoutFillColor = clAlphaColor.clHexToColor('#c9e208'); | Specifies the background color of the selected cell. |
SelectedLayoutFontColor | ProGrid1.SelectedLayoutFontColor = clAlphaColor.clHexToColor('#e29d08'); | Specifies the text color of the selected cell. |
NormalLayoutFillColor | ProGrid1.NormalLayoutFillColor = clAlphaColor.clHexToColor('#de02ed'); | Sets the background color of the odd-numbered rows in the grid. |
NormalLayoutFontColor | ProGrid1.NormalLayoutFontColor = clAlphaColor.clHexToColor('#de02ed'); | Sets the text color of the odd-numbered rows in the grid. |
BandLayoutFillColor | ProGrid1.BandLayoutFillColor = clAlphaColor.clHexToColor('#2bf104'); | Sets the background color of the even-numbered rows in the grid. |
BandLayoutFontColor | ProGrid1.BandLayoutFontColor = clAlphaColor.clHexToColor('#2bf104'); | Sets the text color of the even-numbered rows in the grid. |
ConnectDataSet | ProGrid1.ConnectDataSet(qryJson); | Connects the grid to a dataset. |
tbeOnProGridCellClick | Form1.AddNewEvent(ProGrid1,tbeOnProGridCellClick,'ProGridCellClick'); | Captures single-click events. |
tbeOnProGridCellDblClick | Form1.AddNewEvent(ProGrid1,tbeOnProGridCellDblClick,'ProGridCellDblClick'); | Captures double-click events. |
Example 1: Use Of Dynamic Grid
In this example, the TclProGrid component and other user interface components are dynamically created and configured. Form1 is a form of type TCLForm, onto which a vertical scroll box (TclVertScrollBox) named mainVertSB is added. A label (TclLabel) and a ProGrid (TCLProGrid) are also added. The ProGrid contains 5 columns and 10 rows, with cells dynamically filled in the format "CELL I-J". The visual properties of the ProGrid (header, normal, band, and selected row colors) are customized using specific color codes. Additionally, an event handler named ProGridCellClick is added to capture cell click events in the ProGrid.
var Form1:TCLForm; ProGrid1:TCLProGrid; mainVertSB : TclVertScrollBox; Label1 : TclLabel; I,J:integer; void ProGridCellClick; var FCol,FRow:integer; FSender:TCLProGrid; { FSender = TCLProGrid(Form1.ClSender); FRow = Form1.ClSenderRow; FCol = Form1.ClSenderCol; ShowMessage('Tek Click: '+FSender.Cells[FCol,FRow]); } { Form1 = TCLForm.Create(Self); mainVertSB = Form1.AddNewVertScrollBox(Form1,'mainVertSB'); mainVertSB.Align = alClient; Label1 = Form1.AddNewLabel(mainVertSB,'testLabel1','Dynamic Data Creation'); Label1.Align = alTop; Label1.StyledSettings = ssFamily; Label1.TextSettings.Font.Size = 25; Label1.Height = 100; ProGrid1 = Form1.AddNewProGrid(mainVertSB,'ClProGrid2'); ProGrid1.Align = alTop; ProGrid1.Height = 300; ProGrid1.BeginUpdate; ProGrid1.ColumnCount = 5; ProGrid1.RowCount = 10; ProGrid1.FixedColumns = 1; ProGrid1.FixedRows = 1; ProGrid1.AutoSizeColumns(True,100); for (I = 0 to 5) { for (J = 0 to 10) { ProGrid1.Cells[I,J] = 'CELL ' + IntToStr(I) + '-' + IntToStr(J)+''; ProGrid1.FontSizes[I,J] = 15; ProGrid1.FontStyles[I,J] = 3; ProGrid1.FontNames[I,J] = 'arial'; ProGrid1.RowHeights[J] = 50; ProGrid1.HorzAlignments[I,J] = 1; ProGrid1.VertAlignments[I,J] = 2; } } ProGrid1.FixedLayoutFillColor = clAlphaColor.clHexToColor('#c591a7'); ProGrid1.FixedLayoutFontColor = clAlphaColor.clHexToColor('#a81f1f'); ProGrid1.NormalLayoutFillColor = clAlphaColor.clHexToColor('#374ad7'); ProGrid1.NormalLayoutFontColor = clAlphaColor.clBlack; ProGrid1.BandLayoutFillColor = clAlphaColor.clHexToColor('#ad37d7'); ProGrid1.BandLayoutFontColor = clAlphaColor.clSeashell; ProGrid1.FocusedLayoutFillColor = clAlphaColor.clHexToColor('#02edde'); ProGrid1.FocusedLayoutFontColor = clAlphaColor.clHexToColor('#0c1d1b'); ProGrid1.EndUpdate; Form1.AddNewEvent(ProGrid1,tbeOnProGridCellClick,'ProGridCellClick'); Form1.Run; }
Example 2: Using Grid with SQLite Integration
In the example, a TCLForm is created to perform SQLite database operations and use a dynamic ProGrid component. First, the SqLiteConnectionCreateTable procedure checks if a table named "UserInformation" exists in the database; if not, it creates a new table and inserts test data. Next, the getProGrid procedure retrieves data from the SQLite database, creates a ProGrid component, and displays the data in the grid. An event handler named ProGridCellClick is added to capture cell click events in the ProGrid. The form and other components are configured, and then the form is executed.
var Form1:TCLForm; clProGrid:TCLProGrid; mainVertSB : TclVertScrollBox; Label1 : TclLabel; void ProGridCellClick; var FCol,FRow:integer; FSender:TCLProGrid; { FSender = TCLProGrid(Form1.ClSender); FRow = Form1.ClSenderRow; FCol = Form1.ClSenderCol; ShowMessage('Click: '+FSender.Cells[FCol,FRow]); } void SqLiteInsertData; { try Clomosy.DBSQLiteQuery.Sql.Text = ' INSERT INTO UserInformation (userID, name, surname,v_note) VALUES (123456, ''John'', ''Doe'',85); INSERT INTO UserInformation (userID, name, surname,v_note) VALUES (789456, ''Jane'', ''Smith'',78); INSERT INTO UserInformation (userID, name, surname,v_note) VALUES (753951, ''Michael'', ''Brown'', 88); INSERT INTO UserInformation (userID, name, surname,v_note) VALUES (852654, ''Emily'', ''Davis'', 92); INSERT INTO UserInformation (userID, name, surname,v_note) VALUES (956754, ''Daniel'', ''Wilson'',81); INSERT INTO UserInformation (userID, name, surname,v_note) VALUES (124326, ''Emma'', ''Johnson'',87);'; Clomosy.DBSQLiteQuery.OpenOrExecute; ShowMessage('Adding data to the table was successful!'); except ShowMessage('Exception Class: '+LastExceptionClassName+' Exception Message: '+LastExceptionMessage); } } void SqLiteConnectionCreateTable; var TableExists: Boolean; { try Clomosy.DBSQLiteConnect(Clomosy.AppFilesPath + 'DBUsers.db3', ''); // Check if the table exists Clomosy.DBSQLiteQuery.Sql.Text = 'SELECT name FROM sqlite_master WHERE type="table" AND name="UserInformation";'; Clomosy.DBSQLiteQuery.OpenOrExecute; // Check the results TableExists = not Clomosy.DBSQLiteQuery.Eof; // Create the table if it does not exist if not (TableExists) { Clomosy.DBSQLiteQuery.Sql.Text = 'CREATE TABLE UserInformation(userID INTEGER NOT NULL, name TEXT NOT NULL, surname TEXT NOT NULL, v_note INTEGER NOT NULL)'; Clomosy.DBSQLiteQuery.OpenOrExecute; ShowMessage('Table successfully added to the database!'); SqLiteInsertData; }else { ShowMessage('The Products table already exists.'); } except ShowMessage('Exception Class: '+LastExceptionClassName+' Exception Message: '+LastExceptionMessage); } } void getProGrid; var Qry : TClSQLiteQuery; { try Qry = Clomosy.DBSQLiteQueryWith('SELECT * from UserInformation'); Qry.OpenOrExecute; if (Qry.Found) { clProGrid = Form1.AddNewProGrid(mainVertSB,'clProGrid'); clProGrid.Align = alTop; clProGrid.Options.Selection.Mode = smSingleCell; clProGrid.Height = 200; clProGrid.ConnectDataSet(Qry); clProGrid.AutoSizeColumns(True,100); Form1.AddNewEvent(clProGrid,tbeOnProGridCellClick,'ProGridCellClick'); } except ShowMessage('[01] Exception Class: '+LastExceptionClassName+' Exception Message: '+LastExceptionMessage); } } { Form1 = TCLForm.Create(Self); mainVertSB = Form1.AddNewVertScrollBox(Form1,'mainVertSB'); mainVertSB.Align = alClient; Label1 = Form1.AddNewLabel(mainVertSB,'Label1','SQLITE EXAMPLE'); Label1.Align = alTop; Label1.StyledSettings = ssFamily; Label1.TextSettings.Font.Size = 25; Label1.Height = 100; SqLiteConnectionCreateTable; getProGrid; Form1.Run; }