0

I have encountered a strange issue with cxGrid. After executing a query to fetch all the records, the records show in the grid. Its a simple query:

'select * from mytable order by name asc'

However,if I try and select the first record in the grid,the grid jumps to some random record in the middle of the grid. I can not scroll from the first record in the grid to the one grid jumps to. However, beyond that record I can scroll normally up and down. I can not scroll from the middle upwards nor can I select any record over there. It seems my grid is stuck on the middle record.

If I change DataController to

GridMode = True

then I can scroll without the problem but I loose the functionality of the grid. It is not a dataset issue as when I replace the grid with the normal grid the scrolling is functional.

So I am wondering if this is a bug of some sort or is it a setting in the grid that is turned on/off by accident.

ps. FindPanel is visible.

user3181689
  • 241
  • 6
  • 22

2 Answers2

1

In case it helps, below are the code and DFM of a minimalist cxGrid project which works fine for me and doesn't show the behaviour you describe. If it works for you, too, perhaps it will help you identify what difference in your project is causing your problem.

Code:

type
  TForm1 = class(TForm)
    CDS1: TClientDataSet;
    DataSource1: TDataSource;
    cxGrid1DBTableView1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    CDS1ID: TIntegerField;
    CDS1Name: TStringField;
    cxGrid1DBTableView1ID: TcxGridDBColumn;
    cxGrid1DBTableView1Name: TcxGridDBColumn;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  protected
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
var
  i,
  j,
  ID : Integer;
  Name : String;
begin
  CDS1.CreateDataSet;
  for i := 1 to 26 do begin
    for j:= 1 to 26 do begin
      ID := i * j;
      Name := Chr(Ord('A') + i - 1) + Chr(Ord('A') + j - 1);
      CDS1.InsertRecord([ID, Name]);
    end;
  end;
  CDS1.First;
  Caption := IntToStr(CDS1.RecordCount);

 cxGrid1DBTableView1.DataController.Filter.BeginUpdate;

 try
   cxGrid1DBTableView1.DataController.Filter.Root.AddItem(cxGrid1DBTableView1Name, foLike, '%A', '%A');
 finally
   cxGrid1DBTableView1.DataController.Filter.EndUpdate;
   cxGrid1DBTableView1.DataController.Filter.Active := true;
  end;
end;

DFM:

object Form1: TForm1
  Left = 259
  Top = 103
  AutoScroll = False
  Caption = 'Form1'
  ClientHeight = 314
  ClientWidth = 444
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  Position = poScreenCenter
  Scaled = False
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object cxGrid1: TcxGrid
    Left = 0
    Top = 0
    Width = 444
    Height = 314
    Align = alClient
    TabOrder = 0
    object cxGrid1DBTableView1: TcxGridDBTableView
      Navigator.Buttons.CustomButtons = <>
      DataController.DataSource = DataSource1
      DataController.KeyFieldNames = 'ID'
      DataController.Summary.DefaultGroupSummaryItems = <>
      DataController.Summary.FooterSummaryItems = <>
      DataController.Summary.SummaryGroups = <>
      FilterRow.Visible = True
      OptionsView.GroupByBox = False
      object cxGrid1DBTableView1ID: TcxGridDBColumn
        DataBinding.FieldName = 'ID'
      end
      object cxGrid1DBTableView1Name: TcxGridDBColumn
        DataBinding.FieldName = 'Name'
      end
    end
    object cxGrid1Level1: TcxGridLevel
      GridView = cxGrid1DBTableView1
    end
  end
  object CDS1: TClientDataSet
    Aggregates = <>
    IndexFieldNames = 'Name'
    Params = <>
    Left = 16
    Top = 24
    object CDS1ID: TIntegerField
      FieldName = 'ID'
    end
    object CDS1Name: TStringField
      FieldName = 'Name'
      Size = 40
    end
  end
  object DataSource1: TDataSource
    DataSet = CDS1
    Left = 56
    Top = 24
  end
end
MartynA
  • 30,454
  • 4
  • 32
  • 73
0

The only way I could make this work is to disable the sync mode before executing the query :

cxGrid2DBTableView1.DataController.DataModeController.SyncMode := False;

Just had to remember to enable it back again.

Not the optimal solution but if someone knows a better one, I'd be much obliged.

user3181689
  • 241
  • 6
  • 22