From Clomosy Docs
function AddNewStringGrid(AComponent: TCLComponent; xName: string): TclStringGrid;
AComponent : Specifies the parent of the object to be defined.
xName : The name of the defined component should be written.
TclStringGrid represents a grid control designed to simplify the handling of strings and associated objects.
Add a TclStringGrid object to a form to present textual data in a tabular format. TclStringGrid provides many properties to control the appearance of the grid, as well as events and methods that take advantage of the tabular organization of the grid in responding to user actions.
TclStringGrid introduces the ability to associate an object with each string in the grid. These objects can encapsulate any information or behavior represented by the strings that are presented to the user.
| Feature | Use of | Definition |
|---|---|---|
| TclStringGrid | StringGrid1 : TclStringGrid; | A variable belonging to the TclStringGrid class is created. |
| AddNewStringGrid | StringGrid1 = GridForm1.AddNewStringGrid(GridForm1, 'StringGrid1'); | A new Grid is added to the form. |
| tbeOnGridCellClick | GridForm1.AddNewEvent(StringGrid1, tbeOnGridCellClick, 'OnCellClick'); | This is the event that will be triggered when a cell is clicked. |
| ColumnCount | StringGrid1.ColumnCount | Returns number of columns |
| RowCount | StringGrid1.RowCount | Returns number of rows |
| Width | StringGrid1.Columns[0].Width = 60; | Allows the width of columns to be adjusted. |
| Visible | StringGrid1.Columns[0].Visible = False; | It enables hiding a desired column within the grid. |
| Header | StringGrid1.Columns[0].Header = 'Random Value'; | Headings of each column can be determined. |
| AddNewGridBinding | GridForm1.AddNewGridBinding(xStringGrid,xDataSet,'mylink'); | It can be used to connect a new data set to the created grid structure. |
| RemoveGridBinding | GridForm1.RemoveGridBinding('mylink'); | Data set binding to the grid structure is removed. |
| Cells | StringGrid1.Cells[GridForm1.clSenderCol,GridForm1.clSenderRow] //StringGrid1.Cells[1,2] | It is used to get or set data in a specific cell. |
| clSenderCol | GridForm1.clSenderCol | Returns which column it is in. |
| clSenderRow | GridForm1.clSenderRow | Returns which row it is in. |
| UseDefaultDrawCell | GridForm1.FormGridDefaultDrawCell.UseDefaultDrawCell = True; | In order to use the Grid Default Drawing Cell, it must be activated. |
| ColorControlColID | GridForm1.FormGridDefaultDrawCell.ColorControlColID = 1; | The column id to control the color of the Grid Default Drawing Cell must be entered. |
| ColorControlCellValue | GridForm1.FormGridDefaultDrawCell.ColorControlCellValue = '50'; | The desired value in the column that will control the Grid Default Drawing Cell is assigned. As soon as this value is reached, its color changes. |
| ReadOnly | StringGrid1.ReadOnly = True | It ensures that grid cells are read only (cannot be interfered with). |
Example
var
GridForm:TclForm;
DataSetBtn:TclButton;
MyGrid:TclStringGrid;
void SetupGridColumns;
{
if (MyGrid.ColumnCount>0)
{
MyGrid.Columns[0].Width = 60;
MyGrid.Columns[1].Width = 150;
}
MyGrid.Columns[0].Header = 'Random Value';
MyGrid.Columns[1].Header = 'Date-Time';
}
void onClickBtn;
var
MyDataSet:TClJSonQuery;
{
GridForm.RemoveGridBinding('mylink');
MyDataSet = Clomosy.ClDataSetFromJSON('[{"Col1":"'+IntToStr(Random() * 100)+'","Col2":"'+DateTimeToStr(Now-100)+'"},
{"Col1":"'+IntToStr(Random() * 100)+'","Col2":"'+DateTimeToStr(Now-1)+'"}]');
GridForm.AddNewGridBinding(MyGrid,MyDataSet, 'mylink');
SetupGridColumns;
}
void OnCellClick;
{
ShowMessage(MyGrid.Cells[GridForm.clSenderCol,GridForm.clSenderRow]);
//MyGrid.Cells[1, 2] = 'Merhaba'; // Assigns the value 'Hello' to the cell in column 1 and row 2
}
{
GridForm = TClForm.Create(Self);
MyGrid = GridForm.AddNewStringGrid(GridForm, 'MyGrid');
GridForm.AddNewEvent(MyGrid, tbeOnGridCellClick, 'OnCellClick');
MyGrid.Align = alTop;
MyGrid.ReadOnly = TRUE;
GridForm.FormGridDefaultDrawCell.UseDefaultDrawCell = True;
GridForm.FormGridDefaultDrawCell.ColorControlColID = 0;
GridForm.FormGridDefaultDrawCell.ColorControlCellValue = '40';
DataSetBtn = GridForm.AddNewButton(GridForm, 'DataSetBtn','Add Data');
DataSetBtn.Align = alBottom;
GridForm.AddNewEvent(DataSetBtn, tbeOnClick, 'onClickBtn');
GridForm.Run;
}