QuickStart
Crea un'applicazione VCL, trascina sulla form un TsgcVCLGrid dalla pagina SGC Grid della palette, fai doppio clic sulla form per ottenere FormCreate e scrivi le righe seguenti. Premi F9. La stessa griglia in C++Builder e in un'applicazione .NET WinForms si trova nelle altre schede.
uses
SysUtils, Classes, Controls, Forms,
sgcGrid_Columns, sgcGrid_Data, sgcGrid_VCL;
type
TForm1 = class(TForm)
sgcVCLGrid1: TsgcVCLGrid;
procedure FormCreate(Sender: TObject);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
sgcVCLGrid1.Align := alClient;
sgcVCLGrid1.Columns.Add('Symbol', 'Symbol');
sgcVCLGrid1.Columns.Add('Price', 'Price', gdtFloat).DisplayFormat := '0.00';
sgcVCLGrid1.Columns.Add('Volume', 'Volume', gdtInteger);
sgcVCLGrid1.Data.AppendRow('MSFT', ['MSFT', 412.5, 1200]);
sgcVCLGrid1.Data.AppendRow('AAPL', ['AAPL', 228.1, 3400]);
sgcVCLGrid1.Data.UpdateRow('MSFT', ['Price', 'Volume'], [413.1, 1350]);
end;
AppendRow riceve i valori nell'ordine delle colonne. UpdateRow riceve i nomi dei campi, quindi un messaggio che contiene solo un prezzo modifica solo il prezzo, e una chiave non ancora esistente viene inserita. Le colonne si possono aggiungere anche in design-time con l'editor Columns, e un TsgcGridSource_DataSet della stessa pagina della palette riempie la griglia da qualsiasi TDataSet.
#include <vcl.h>
#include "sgcGrid_Columns.hpp"
#include "sgcGrid_Data.hpp"
#include "sgcGrid_VCL.hpp"
void __fastcall CreateGrid(TForm *Form)
{
TsgcVCLGrid *Grid = new TsgcVCLGrid(Form);
Grid->Parent = Form;
Grid->Align = alClient;
Grid->Columns->Add("Symbol", "Symbol", gdtText);
Grid->Columns->Add("Price", "Price", gdtFloat)->DisplayFormat = "0.00";
Grid->Columns->Add("Volume", "Volume", gdtInteger);
Grid->Data->AppendRow("MSFT", OPENARRAY(Variant,
(Variant("MSFT"), Variant(412.5), Variant(1200))));
Grid->Data->AppendRow("AAPL", OPENARRAY(Variant,
(Variant("AAPL"), Variant(228.1), Variant(3400))));
}
C++Builder usa gli stessi componenti tramite gli header e le librerie generati dall'installer di C++Builder. Gli open array di Delphi si passano con la macro OPENARRAY. Oppure salta il codice, trascina il TsgcVCLGrid sulla form e imposta le colonne nell'Object Inspector.
using System;
using System.Windows.Forms;
using esegece.sgcGrid;
internal static class Program
{
[STAThread]
private static void Main()
{
Application.EnableVisualStyles();
Form oForm = new Form { Text = "My first sgcUI form", Width = 640, Height = 360 };
TsgcWinFormsGrid oGrid = new TsgcWinFormsGrid { Dock = DockStyle.Fill };
oGrid.Columns.Add("symbol", "Symbol");
oGrid.Columns.Add("price", "Price", TsgcGridDataType.gdtFloat).DisplayFormat = "0.00";
oGrid.Columns.Add("volume", "Volume", TsgcGridDataType.gdtInteger);
oGrid.Data.AppendRow("MSFT", "MSFT", 412.5, 1200);
oGrid.Data.AppendRow("AAPL", "AAPL", 228.1, 3400);
oGrid.Data.UpdateRow("MSFT", new[] { "price", "volume" }, new object[] { 413.1, 1350 });
oForm.Controls.Add(oGrid);
Application.Run(oForm);
}
}
I nomi delle classi seguono quelli di Delphi: TsgcWinFormsGrid per WinForms, TsgcWpfGrid per WPF, con gli stessi membri Columns e Data in ciascuna. I pacchetti WinForms hanno come target .NET Framework 4.7.2 e .NET 8, 9 e 10 per Windows.