Hi all.
Using TCxGrid for a lot of stuff over the years. But recently cutomers want "more" :-)
So I've tried to make some of my apps more user friendly by adding the ability to append records "arrow down" directly in the grid.
This is 90% working as intended and customers are happy.
BUT !
Trying to use "arrow up" to undo the insert gives me all kinds off trouble!
Consider this scenario:
1 table - 1 Primary key column calld ID. And with 2 NOT NULL columns (lets call them C2 and C3).
The grid is created with 2 views - and the grid is, not in grid mode, and it is bound.
- one is grouped by C2 and not showing C3.
- the other one is grouped by C3 and not showing C2.
Trying to append records will leave us to manually insert data into either C2 or C3. I've done that on the dataset "onbeforeinsert". And it works :-)
But when I try to cancel the insert, the grid obviously is in a state where it thinks we should post whatever changes (cause we have made 1 change) there is to the underlying DB.
At this point I would like to send a CANCEL to the dataset (which is in dsinsert mode). But to be able to do this I would have to catch the event before it is posted.
This is where I fail - I cannot find a proper event to fire my cancel statement in!
Can anyone help me - or atleast concur that there is a problem here.
Kind Regards
Bjarne Rasmussen
Trige & Tang
www.trigetang.dk
PROJECT SOURCE TO TEST THIS :
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
cxEdit, DB, cxDBData, cxGridCustomTableView, cxGridTableView,
cxGridDBTableView, dxmdaset, cxGridLevel, cxClasses, cxControls,
cxGridCustomView, cxGrid, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
cxGrid1DBTableView1: TcxGridDBTableView;
cxGrid1Level1: TcxGridLevel;
cxGrid1: TcxGrid;
dxMemData1: TdxMemData;
dxMemData1C1: TIntegerField;
dxMemData1C2: TIntegerField;
dxMemData1Tekst: TStringField;
DataSource1: TDataSource;
cxGrid1DBTableView1RecId: TcxGridDBColumn;
cxGrid1DBTableView1C1: TcxGridDBColumn;
cxGrid1DBTableView1C2: TcxGridDBColumn;
cxGrid1DBTableView1Tekst: TcxGridDBColumn;
cxGrid1DBTableView2: TcxGridDBTableView;
cxGrid1DBTableView2RecId: TcxGridDBColumn;
cxGrid1DBTableView2C1: TcxGridDBColumn;
cxGrid1DBTableView2C2: TcxGridDBColumn;
cxGrid1DBTableView2Tekst: TcxGridDBColumn;
RadioGroup1: TRadioGroup;
procedure RadioGroup1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
dxMemData1.Open;
end;
procedure TForm1.RadioGroup1Click(Sender: TObject);
begin
case RadioGroup1.ItemIndex of
0 : cxGrid1Level1.GridView := cxGrid1DBTableView1;
1 : cxGrid1Level1.GridView := cxGrid1DBTableView2;
end;
end;
end.
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 591
ClientWidth = 729
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object cxGrid1: TcxGrid
Left = 8
Top = 80
Width = 689
Height = 489
TabOrder = 0
object cxGrid1DBTableView1: TcxGridDBTableView
NavigatorButtons.ConfirmDelete = False
DataController.DataSource = DataSource1
DataController.Summary.DefaultGroupSummaryItems = <>
DataController.Summary.FooterSummaryItems = <>
DataController.Summary.SummaryGroups = <>
OptionsData.Appending = True
OptionsView.GroupByBox = False
object cxGrid1DBTableView1RecId: TcxGridDBColumn
DataBinding.FieldName = 'RecId'
Visible = False
end
object cxGrid1DBTableView1C1: TcxGridDBColumn
DataBinding.FieldName = 'C1'
Width = 117
end
object cxGrid1DBTableView1C2: TcxGridDBColumn
DataBinding.FieldName = 'C2'
Visible = False
end
object cxGrid1DBTableView1Tekst: TcxGridDBColumn
DataBinding.FieldName = 'Tekst'
Width = 391
end
end
object cxGrid1DBTableView2: TcxGridDBTableView
NavigatorButtons.ConfirmDelete = False
DataController.DataSource = DataSource1
DataController.Summary.DefaultGroupSummaryItems = <>
DataController.Summary.FooterSummaryItems = <>
DataController.Summary.SummaryGroups = <>
OptionsData.Appending = True
OptionsView.GroupByBox = False
object cxGrid1DBTableView2RecId: TcxGridDBColumn
DataBinding.FieldName = 'RecId'
Visible = False
end
object cxGrid1DBTableView2C1: TcxGridDBColumn
DataBinding.FieldName = 'C1'
Visible = False
end
object cxGrid1DBTableView2C2: TcxGridDBColumn
DataBinding.FieldName = 'C2'
end
object cxGrid1DBTableView2Tekst: TcxGridDBColumn
DataBinding.FieldName = 'Tekst'
end
end
object cxGrid1Level1: TcxGridLevel
GridView = cxGrid1DBTableView1
end
end
object RadioGroup1: TRadioGroup
Left = 8
Top = 9
Width = 113
Height = 65
Caption = 'Select View'
ItemIndex = 0
Items.Strings = (
'View 1'
'View 2')
TabOrder = 1
OnClick = RadioGroup1Click
end
object dxMemData1: TdxMemData
Indexes = <>
SortOptions = []
Left = 608
Top = 32
object dxMemData1C1: TIntegerField
FieldName = 'C1'
Required = True
end
object dxMemData1C2: TIntegerField
FieldName = 'C2'
Required = True
end
object dxMemData1Tekst: TStringField
FieldName = 'Tekst'
end
end
object DataSource1: TDataSource
DataSet = dxMemData1
Left = 568
Top = 32
end
end