I have two cxgrid's on my form (cxGrid1 and cxGrid2). Both have the NewItemRow.Visible.
Now, I want to remove NewItemRow from cxGrid2. Calling :
cxGridDBTableView1.NewItemRow.Visible:=False;
removes NewItemRow from cxGrid1 and not from the one I want (cxGrid2). How can I apply this to cxGrid2 ?
It is obvious from your q and your replies to readers' comments that there is something amiss in the declaration of your form. A newly created form with cxGrids placed on it in the usual way (by selecting the cxGrid on the Component Palette and dropping two instances of it onto the form) does not exhibit the compilation problem, nor the aberrant behaviour you describe. Try it and you will see what I mean.
Below is the code and .DFM extract of a project which has two TcxGrids, one with a visible NewItemRow, one without. This example project is for D7 using v.15 of the cxGrid, which is the highest version number which supports D7. I've done it in D7 as you didn't say what Delphi version you are using.
I've deliberately set up as many of the component properties, etc, as I could in code, so you can see what is going on and how it is done.
If you try it, you will find that it compiles without the error message you mention in one of your comments and behaves as intended. Therefore I can only assume that there is some error in your naming or declaration of components and/or in your code that we readers can't see in what you've included in your q.
The best I can suggest you do to unravel your problem is to start with a blank form and drop 2 cxGrids onto it. Save and view the resulting DFM and confirm to yourself that the 2cxGrids and their subcomponents (cxGridDBTableView and cxGridLevel) are correctly and distinctly named, and then do a DIFF between that DFM and your project's one to identify where they diverge.
type
TForm1 = class(TForm)
cxGrid1DBTableView1: TcxGridDBTableView;
cxGrid1Level1: TcxGridLevel;
cxGrid1: TcxGrid;
cxGrid2DBTableView1: TcxGridDBTableView;
cxGrid2Level1: TcxGridLevel;
cxGrid2: TcxGrid;
CDS1: TClientDataSet;
DataSource1: TDataSource;
DBNavigator1: TDBNavigator;
DBNavigator2: TDBNavigator;
DBGrid1: TDBGrid;
CDS1ID: TIntegerField;
CDS1Name: TStringField;
procedure FormCreate(Sender: TObject);
private
public
end;
[...]
procedure TForm1.FormCreate(Sender: TObject);
var
Field : TField;
begin
Field := TIntegerField.Create(Self);
Field.FieldName := 'ID';
Field.FieldKind := fkData;
Field.DataSet := CDS1;
Field := TStringField.Create(Self);
Field.FieldName := 'Name';
Field.Size := 20;
Field.FieldKind := fkData;
Field.DataSet := CDS1;
CDS1.CreateDataSet;
CDS1.InsertRecord([1, 'One']);
DBNavigator1.DataSource := DataSource1;
DBNavigator2.DataSource := DataSource1;
cxGrid1DBTableView1.DataController.DataSource := DataSource1;
cxGrid2DBTableView1.DataController.DataSource := DataSource1;
// The following creates default columns for the grids
cxGrid1DBTableView1.DataController.CreateAllItems;
cxGrid2DBTableView1.DataController.CreateAllItems;
cxGrid1DBTableView1.NewItemRow.Visible:= True;
cxGrid2DBTableView1.NewItemRow.Visible:= False;
end;
DFM extract
object Form1: TForm1
[...]
object cxGrid1: TcxGrid
Left = 24
Top = 16
Width = 250
Height = 200
TabOrder = 0
object cxGrid1DBTableView1: TcxGridDBTableView
Navigator.Buttons.CustomButtons = <>
DataController.DataSource = DataSource1
DataController.KeyFieldNames = 'ID'
DataController.Summary.DefaultGroupSummaryItems = <>
DataController.Summary.FooterSummaryItems = <>
DataController.Summary.SummaryGroups = <>
end
object cxGrid1Level1: TcxGridLevel
GridView = cxGrid1DBTableView1
end
end
object cxGrid2: TcxGrid
Left = 32
Top = 280
Width = 250
Height = 200
TabOrder = 1
object cxGrid2DBTableView1: TcxGridDBTableView
Navigator.Buttons.CustomButtons = <>
DataController.DataSource = DataSource1
DataController.KeyFieldNames = 'ID'
DataController.Summary.DefaultGroupSummaryItems = <>
DataController.Summary.FooterSummaryItems = <>
DataController.Summary.SummaryGroups = <>
end
object cxGrid2Level1: TcxGridLevel
GridView = cxGrid2DBTableView1
end
end
object DBNavigator1: TDBNavigator
Left = 40
Top = 232
Width = 240
Height = 25
TabOrder = 2
end
object DBNavigator2: TDBNavigator
Left = 40
Top = 496
Width = 240
Height = 25
TabOrder = 3
end
object CDS1: TClientDataSet
Aggregates = <>
Params = <>
end
object DataSource1: TDataSource
DataSet = CDS1
end