QuickStart
Utwórz aplikację VCL, upuść na formularz komponent TsgcVCLGrid ze strony palety SGC Grid, kliknij formularz dwukrotnie, aby uzyskać FormCreate, i wpisz poniższe linie. Naciśnij F9. Ta sama siatka w C++Builder i w aplikacji .NET WinForms jest na pozostałych kartach.
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 przyjmuje wartości w kolejności kolumn. UpdateRow przyjmuje nazwy pól, więc komunikat niosący tylko cenę zmienia wyłącznie cenę, a klucz, który jeszcze nie istnieje, jest wstawiany. Kolumny można też dodać w czasie projektowania za pomocą edytora Columns, a komponent TsgcGridSource_DataSet z tej samej strony palety wypełnia siatkę z dowolnego 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 używa tych samych komponentów poprzez nagłówki i biblioteki budowane przez instalator C++Builder. Otwarte tablice Delphi przekazuje się za pomocą makra OPENARRAY. Możesz też pominąć kod, upuścić TsgcVCLGrid na formularz i ustawić kolumny w Inspektorze obiektów.
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);
}
}
Nazwy klas odpowiadają nazwom z Delphi: TsgcWinFormsGrid dla WinForms, TsgcWpfGrid dla WPF, a każda ma te same składowe Columns i Data. Pakiety WinForms celują w .NET Framework 4.7.2 oraz .NET 8, 9 i 10 dla Windows.