exgrid - sample code |
How can I add a SUM field? VBA (MS Access, Excell...) With Grid1 .BeginUpdate .Columns.Add("Numbers").SortType = 1 With .Items .AddItem 1 .AddItem 2 .AddItem 3 .AddItem 4 h = .AddItem("sum(all,dir,dbl(%0))") .SortableItem(h) = False .CellValueFormat(h,0) = 4 .CellHAlignment(h,0) = 2 .FormatCell(h,0) = "'SUM: '+value" End With .EndUpdate End With VB6 With Grid1 .BeginUpdate .Columns.Add("Numbers").SortType = SortNumeric With .Items .AddItem 1 .AddItem 2 .AddItem 3 .AddItem 4 h = .AddItem("sum(all,dir,dbl(%0))") .SortableItem(h) = False .CellValueFormat(h,0) = exTotalField .CellHAlignment(h,0) = RightAlignment .FormatCell(h,0) = "'SUM: '+value" End With .EndUpdate End With VB.NET Dim h With Exgrid1 .BeginUpdate() .Columns.Add("Numbers").SortType = exontrol.EXGRIDLib.SortTypeEnum.SortNumeric With .Items .AddItem(1) .AddItem(2) .AddItem(3) .AddItem(4) h = .AddItem("sum(all,dir,dbl(%0))") .set_SortableItem(h,False) .set_CellValueFormat(h,0,exontrol.EXGRIDLib.ValueFormatEnum.exTotalField) .set_CellHAlignment(h,0,exontrol.EXGRIDLib.AlignmentEnum.RightAlignment) .set_FormatCell(h,0,"'SUM: '+value") End With .EndUpdate() End With VB.NET for /COM Dim h With AxGrid1 .BeginUpdate() .Columns.Add("Numbers").SortType = EXGRIDLib.SortTypeEnum.SortNumeric With .Items .AddItem(1) .AddItem(2) .AddItem(3) .AddItem(4) h = .AddItem("sum(all,dir,dbl(%0))") .SortableItem(h) = False .CellValueFormat(h,0) = EXGRIDLib.ValueFormatEnum.exTotalField .CellHAlignment(h,0) = EXGRIDLib.AlignmentEnum.RightAlignment .FormatCell(h,0) = "'SUM: '+value" End With .EndUpdate() End With C++ /* Copy and paste the following directives to your header file as it defines the namespace 'EXGRIDLib' for the library: 'ExGrid 1.0 Control Library' #import <ExGrid.dll> using namespace EXGRIDLib; */ EXGRIDLib::IGridPtr spGrid1 = GetDlgItem(IDC_GRID1)->GetControlUnknown(); spGrid1->BeginUpdate(); ((EXGRIDLib::IColumnPtr)(spGrid1->GetColumns()->Add(L"Numbers")))->PutSortType(EXGRIDLib::SortNumeric); EXGRIDLib::IItemsPtr var_Items = spGrid1->GetItems(); var_Items->AddItem(long(1)); var_Items->AddItem(long(2)); var_Items->AddItem(long(3)); var_Items->AddItem(long(4)); long h = var_Items->AddItem("sum(all,dir,dbl(%0))"); var_Items->PutSortableItem(h,VARIANT_FALSE); var_Items->PutCellValueFormat(h,long(0),EXGRIDLib::exTotalField); var_Items->PutCellHAlignment(h,long(0),EXGRIDLib::RightAlignment); var_Items->PutFormatCell(h,long(0),L"'SUM: '+value"); spGrid1->EndUpdate(); C++ Builder Grid1->BeginUpdate(); Grid1->Columns->Add(L"Numbers")->SortType = Exgridlib_tlb::SortTypeEnum::SortNumeric; Exgridlib_tlb::IItemsPtr var_Items = Grid1->Items; var_Items->AddItem(TVariant(1)); var_Items->AddItem(TVariant(2)); var_Items->AddItem(TVariant(3)); var_Items->AddItem(TVariant(4)); long h = var_Items->AddItem(TVariant("sum(all,dir,dbl(%0))")); var_Items->set_SortableItem(h,false); var_Items->set_CellValueFormat(TVariant(h),TVariant(0),Exgridlib_tlb::ValueFormatEnum::exTotalField); var_Items->set_CellHAlignment(TVariant(h),TVariant(0),Exgridlib_tlb::AlignmentEnum::RightAlignment); var_Items->set_FormatCell(TVariant(h),TVariant(0),L"'SUM: '+value"); Grid1->EndUpdate(); C# exgrid1.BeginUpdate(); (exgrid1.Columns.Add("Numbers") as exontrol.EXGRIDLib.Column).SortType = exontrol.EXGRIDLib.SortTypeEnum.SortNumeric; exontrol.EXGRIDLib.Items var_Items = exgrid1.Items; var_Items.AddItem(1); var_Items.AddItem(2); var_Items.AddItem(3); var_Items.AddItem(4); int h = var_Items.AddItem("sum(all,dir,dbl(%0))"); var_Items.set_SortableItem(h,false); var_Items.set_CellValueFormat(h,0,exontrol.EXGRIDLib.ValueFormatEnum.exTotalField); var_Items.set_CellHAlignment(h,0,exontrol.EXGRIDLib.AlignmentEnum.RightAlignment); var_Items.set_FormatCell(h,0,"'SUM: '+value"); exgrid1.EndUpdate(); JavaScript <OBJECT classid="clsid:101EE60F-7B07-48B0-A13A-F32BAE7DA165" id="Grid1"></OBJECT> <SCRIPT LANGUAGE="JScript"> Grid1.BeginUpdate(); Grid1.Columns.Add("Numbers").SortType = 1; var var_Items = Grid1.Items; var_Items.AddItem(1); var_Items.AddItem(2); var_Items.AddItem(3); var_Items.AddItem(4); var h = var_Items.AddItem("sum(all,dir,dbl(%0))"); var_Items.SortableItem(h) = false; var_Items.CellValueFormat(h,0) = 4; var_Items.CellHAlignment(h,0) = 2; var_Items.FormatCell(h,0) = "'SUM: '+value"; Grid1.EndUpdate(); </SCRIPT> C# for /COM axGrid1.BeginUpdate(); (axGrid1.Columns.Add("Numbers") as EXGRIDLib.Column).SortType = EXGRIDLib.SortTypeEnum.SortNumeric; EXGRIDLib.Items var_Items = axGrid1.Items; var_Items.AddItem(1); var_Items.AddItem(2); var_Items.AddItem(3); var_Items.AddItem(4); int h = var_Items.AddItem("sum(all,dir,dbl(%0))"); var_Items.set_SortableItem(h,false); var_Items.set_CellValueFormat(h,0,EXGRIDLib.ValueFormatEnum.exTotalField); var_Items.set_CellHAlignment(h,0,EXGRIDLib.AlignmentEnum.RightAlignment); var_Items.set_FormatCell(h,0,"'SUM: '+value"); axGrid1.EndUpdate(); X++ (Dynamics Ax 2009) public void init() { COM com_Items; anytype var_Items; int h; ; super(); exgrid1.BeginUpdate(); COM::createFromVariant(exgrid1.Columns().Add("Numbers")).SortType(1/*SortNumeric*/); var_Items = exgrid1.Items(); com_Items = var_Items; com_Items.AddItem(COMVariant::createFromInt(1)); com_Items.AddItem(COMVariant::createFromInt(2)); com_Items.AddItem(COMVariant::createFromInt(3)); com_Items.AddItem(COMVariant::createFromInt(4)); h = com_Items.AddItem("sum(all,dir,dbl(%0))"); com_Items.SortableItem(h,false); com_Items.CellValueFormat(h,COMVariant::createFromInt(0),4/*exTotalField*/); com_Items.CellHAlignment(h,COMVariant::createFromInt(0),2/*RightAlignment*/); com_Items.FormatCell(h,COMVariant::createFromInt(0),"'SUM: '+value"); exgrid1.EndUpdate(); } Delphi 8 (.NET only) with AxGrid1 do begin BeginUpdate(); (Columns.Add('Numbers') as EXGRIDLib.Column).SortType := EXGRIDLib.SortTypeEnum.SortNumeric; with Items do begin AddItem(TObject(1)); AddItem(TObject(2)); AddItem(TObject(3)); AddItem(TObject(4)); h := AddItem('sum(all,dir,dbl(%0))'); SortableItem[h] := False; CellValueFormat[TObject(h),TObject(0)] := EXGRIDLib.ValueFormatEnum.exTotalField; CellHAlignment[TObject(h),TObject(0)] := EXGRIDLib.AlignmentEnum.RightAlignment; FormatCell[TObject(h),TObject(0)] := '''SUM: ''+value'; end; EndUpdate(); end Delphi (standard) with Grid1 do begin BeginUpdate(); (IUnknown(Columns.Add('Numbers')) as EXGRIDLib_TLB.Column).SortType := EXGRIDLib_TLB.SortNumeric; with Items do begin AddItem(OleVariant(1)); AddItem(OleVariant(2)); AddItem(OleVariant(3)); AddItem(OleVariant(4)); h := AddItem('sum(all,dir,dbl(%0))'); SortableItem[h] := False; CellValueFormat[OleVariant(h),OleVariant(0)] := EXGRIDLib_TLB.exTotalField; CellHAlignment[OleVariant(h),OleVariant(0)] := EXGRIDLib_TLB.RightAlignment; FormatCell[OleVariant(h),OleVariant(0)] := '''SUM: ''+value'; end; EndUpdate(); end VFP with thisform.Grid1 .BeginUpdate .Columns.Add("Numbers").SortType = 1 with .Items .AddItem(1) .AddItem(2) .AddItem(3) .AddItem(4) h = .AddItem("sum(all,dir,dbl(%0))") .SortableItem(h) = .F. .CellValueFormat(h,0) = 4 .CellHAlignment(h,0) = 2 .FormatCell(h,0) = "'SUM: '+value" endwith .EndUpdate endwith dBASE Plus local h,oGrid,var_Column,var_Items oGrid = form.Activex1.nativeObject oGrid.BeginUpdate() // oGrid.Columns.Add("Numbers").SortType = 1 var_Column = oGrid.Columns.Add("Numbers") with (oGrid) TemplateDef = [Dim var_Column] TemplateDef = var_Column Template = [var_Column.SortType = 1] endwith var_Items = oGrid.Items var_Items.AddItem(1) var_Items.AddItem(2) var_Items.AddItem(3) var_Items.AddItem(4) h = var_Items.AddItem("sum(all,dir,dbl(%0))") // var_Items.SortableItem(h) = false with (oGrid) TemplateDef = [Dim var_Items,h] TemplateDef = var_Items TemplateDef = h Template = [var_Items.SortableItem(h) = false] endwith // var_Items.CellValueFormat(h,0) = 4 with (oGrid) TemplateDef = [Dim var_Items,h] TemplateDef = var_Items TemplateDef = h Template = [var_Items.CellValueFormat(h,0) = 4] endwith // var_Items.CellHAlignment(h,0) = 2 with (oGrid) TemplateDef = [Dim var_Items,h] TemplateDef = var_Items TemplateDef = h Template = [var_Items.CellHAlignment(h,0) = 2] endwith // var_Items.FormatCell(h,0) = "'SUM: '+value" with (oGrid) TemplateDef = [Dim var_Items,h] TemplateDef = var_Items TemplateDef = h Template = [var_Items.FormatCell(h,0) = "'SUM: '+value"] endwith oGrid.EndUpdate() XBasic (Alpha Five) Dim h as N Dim oGrid as P Dim var_Column as P Dim var_Items as P oGrid = topparent:CONTROL_ACTIVEX1.activex oGrid.BeginUpdate() ' oGrid.Columns.Add("Numbers").SortType = 1 var_Column = oGrid.Columns.Add("Numbers") oGrid.TemplateDef = "Dim var_Column" oGrid.TemplateDef = var_Column oGrid.Template = "var_Column.SortType = 1" var_Items = oGrid.Items var_Items.AddItem(1) var_Items.AddItem(2) var_Items.AddItem(3) var_Items.AddItem(4) h = var_Items.AddItem("sum(all,dir,dbl(%0))") ' var_Items.SortableItem(h) = .f. oGrid.TemplateDef = "Dim var_Items,h" oGrid.TemplateDef = var_Items oGrid.TemplateDef = h oGrid.Template = "var_Items.SortableItem(h) = False" ' var_Items.CellValueFormat(h,0) = 4 oGrid.TemplateDef = "Dim var_Items,h" oGrid.TemplateDef = var_Items oGrid.TemplateDef = h oGrid.Template = "var_Items.CellValueFormat(h,0) = 4" ' var_Items.CellHAlignment(h,0) = 2 oGrid.TemplateDef = "Dim var_Items,h" oGrid.TemplateDef = var_Items oGrid.TemplateDef = h oGrid.Template = "var_Items.CellHAlignment(h,0) = 2" ' var_Items.FormatCell(h,0) = "'SUM: '+value" oGrid.TemplateDef = "Dim var_Items,h" oGrid.TemplateDef = var_Items oGrid.TemplateDef = h oGrid.Template = "var_Items.FormatCell(h,0) = \"'SUM: '+value\"" oGrid.EndUpdate() Visual Objects local var_Items as IItems local h as USUAL oDCOCX_Exontrol1:BeginUpdate() IColumn{oDCOCX_Exontrol1:Columns:Add("Numbers")}:SortType := SortNumeric var_Items := oDCOCX_Exontrol1:Items var_Items:AddItem(1) var_Items:AddItem(2) var_Items:AddItem(3) var_Items:AddItem(4) h := var_Items:AddItem("sum(all,dir,dbl(%0))") var_Items:[SortableItem,h] := false var_Items:[CellValueFormat,h,0] := exTotalField var_Items:[CellHAlignment,h,0] := RightAlignment var_Items:[FormatCell,h,0] := "'SUM: '+value" oDCOCX_Exontrol1:EndUpdate() PowerBuilder OleObject oGrid,var_Items any h oGrid = ole_1.Object oGrid.BeginUpdate() oGrid.Columns.Add("Numbers").SortType = 1 var_Items = oGrid.Items var_Items.AddItem(1) var_Items.AddItem(2) var_Items.AddItem(3) var_Items.AddItem(4) h = var_Items.AddItem("sum(all,dir,dbl(%0))") var_Items.SortableItem(h,false) var_Items.CellValueFormat(h,0,4) var_Items.CellHAlignment(h,0,2) var_Items.FormatCell(h,0,"'SUM: '+value") oGrid.EndUpdate() Visual DataFlex Procedure OnCreate Forward Send OnCreate Send ComBeginUpdate Variant voColumns Get ComColumns to voColumns Handle hoColumns Get Create (RefClass(cComColumns)) to hoColumns Set pvComObject of hoColumns to voColumns Variant voColumn Get ComAdd of hoColumns "Numbers" to voColumn Handle hoColumn Get Create (RefClass(cComColumn)) to hoColumn Set pvComObject of hoColumn to voColumn Set ComSortType of hoColumn to OLESortNumeric Send Destroy to hoColumn Send Destroy to hoColumns Variant voItems Get ComItems to voItems Handle hoItems Get Create (RefClass(cComItems)) to hoItems Set pvComObject of hoItems to voItems Get ComAddItem of hoItems 1 to Nothing Get ComAddItem of hoItems 2 to Nothing Get ComAddItem of hoItems 3 to Nothing Get ComAddItem of hoItems 4 to Nothing Variant h Get ComAddItem of hoItems "sum(all,dir,dbl(%0))" to h Set ComSortableItem of hoItems h to False Set ComCellValueFormat of hoItems h 0 to OLEexTotalField Set ComCellHAlignment of hoItems h 0 to OLERightAlignment Set ComFormatCell of hoItems h 0 to "'SUM: '+value" Send Destroy to hoItems Send ComEndUpdate End_Procedure XBase++ #include "AppEvent.ch" #include "ActiveX.ch" PROCEDURE Main LOCAL oForm LOCAL nEvent := 0, mp1 := NIL, mp2 := NIL, oXbp := NIL LOCAL oGrid LOCAL oItems LOCAL h oForm := XbpDialog():new( AppDesktop() ) oForm:drawingArea:clipChildren := .T. oForm:create( ,,{100,100}, {640,480},, .F. ) oForm:close := {|| PostAppEvent( xbeP_Quit )} oGrid := XbpActiveXControl():new( oForm:drawingArea ) oGrid:CLSID := "Exontrol.Grid.1" /*{101EE60F-7B07-48B0-A13A-F32BAE7DA165}*/ oGrid:create(,, {10,60},{610,370} ) oGrid:BeginUpdate() oGrid:Columns():Add("Numbers"):SortType := 1/*SortNumeric*/ oItems := oGrid:Items() oItems:AddItem(1) oItems:AddItem(2) oItems:AddItem(3) oItems:AddItem(4) h := oItems:AddItem("sum(all,dir,dbl(%0))") oItems:SetProperty("SortableItem",h,.F.) oItems:SetProperty("CellValueFormat",h,0,4/*exTotalField*/) oItems:SetProperty("CellHAlignment",h,0,2/*RightAlignment*/) oItems:SetProperty("FormatCell",h,0,"'SUM: '+value") oGrid:EndUpdate() oForm:Show() DO WHILE nEvent != xbeP_Quit nEvent := AppEvent( @mp1, @mp2, @oXbp ) oXbp:handleEvent( nEvent, mp1, mp2 ) ENDDO RETURN |