Project JEDI - Issue Tracker
Mantis Bugtracker

Viewing Issue Simple Details Jump to Notes ] View Advanced ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0002096 [JEDI VCL] 00 JVCL Components major always 2004-08-26 02:43 2005-04-01 05:51
Reporter davalv View Status public  
Assigned To obones
Priority normal Resolution fixed  
Status resolved   Product Version
Summary 0002096: JvDBGrid and sorting lookup fields
Description Linking JvDBGrid with datasets containing lookup fields and on sorting lookup fields (by clicking column title) launch exception and doesn't sort column.
Additional Information This is the OnTitleClick code for JvDBGrid:

procedure TForm_Barche.BarcheDBGridTitleClick(Column: TColumn);
  BarcheDBGrid.SortedField:= Column.FieldName;

  if Main_DataModule.BarcheADOTable.Sort = BarcheDBGrid.SortedField + ' ASC' then begin
      Main_DataModule.BarcheADOTable.Sort:= BarcheDBGrid.SortedField + ' DESC';
    BarcheDBGrid.SortMarker:= smDown;
  else begin
      Main_DataModule.BarcheADOTable.Sort:= BarcheDBGrid.SortedField + ' ASC';
    BarcheDBGrid.SortMarker:= smUp;
Tags No tags attached.
Attached Files

- Relationships

-  Notes
davalv (reporter)
2004-08-26 02:51

The exception is launched in JvDBGrid unit in this function:

procedure TJvDBGrid.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  Cell: TGridCoord;
  ACol: Longint;
  DoClick: Boolean;
  Cell := MouseCoord(X, Y);
  if FTracking and (FPressedCol <> nil) then
    DoClick := PtInRect(Rect(0, 0, ClientWidth, ClientHeight), {Types.} Point(X, Y)) and
      (Cell.Y < TitleOffset) and
      (FPressedCol = GetMasterColumn(Cell.X, Cell.Y));
    if DoClick then
      ACol := Cell.X;
      if dgIndicator in Options then
      if (DataLink <> nil) and DataLink.Active and (ACol >= 0) and
        (ACol < Columns.Count) then
        DoTitleClick(FPressedCol.Index, FPressedCol.Field);
  if FSwapButtons then
    FSwapButtons := False;
    MouseCapture := False;
    if Button = mbRight then
      Button := mbLeft;
  // Polaris
  if (Button = mbLeft) and (FGridState = gsColSizing) and
    (FSizingIndex + Byte(not (dgIndicator in Options)) <= FixedCols) then
// and not AutoSizeColumns
    ColWidths[FSizingIndex] := GetMinColWidth(X - FSizingOfs - CellRect(FSizingIndex, 0).Left);
    FGridState := gsNormal;
// Exit;
  // Polaris

  if FTitleArrow and (Button = mbLeft) and
    (dgTitles in Options) and (dgIndicator in Options) and
    (Cell.X = 0) and (Cell.Y = 0) and DataLink.Active then
    ShowSelectColumnClick; // Selection of columns

  inherited MouseUp(Button, Shift, X, Y); // <=================== EXCEPTION
davalv (reporter)
2004-08-26 03:06

This is a better code:

procedure TForm_Barche.BarcheDBGridTitleClick(Column: TColumn);
  BarcheDBGrid.SortedField:= Column.FieldName;

  if TADOTable(BarcheDBGrid.DataSource.DataSet).Sort = BarcheDBGrid.SortedField + ' ASC' then begin
    TADOTable(BarcheDBGrid.DataSource.DataSet).Sort:= BarcheDBGrid.SortedField + ' DESC';
    BarcheDBGrid.SortMarker:= smDown;
  else begin
    TADOTable(BarcheDBGrid.DataSource.DataSet).Sort:= BarcheDBGrid.SortedField + ' ASC';
    BarcheDBGrid.SortMarker:= smUp;
anonymous (viewer)
2004-09-09 02:03

You cannot sort this kind of field. This is not a DBGrid limitation but an ADO one (try to sort with ORDER BY instead).
davalv (reporter)
2004-09-09 07:15

I suggest to use this simple code to prevent exceptions:

  if Column.Field.FieldKind = fkLookup then Exit;
anonymous (viewer)
2004-09-09 08:32

I decided to put all the sorting stuff in JvDBUltimGrid (from my point of view, the sorting implemented in JvDBGrid is really crappy and will not work with most of my apps but I let it there for other users and write what I need in JvDBUltimGrid). In JvDBUltimGrid, I raise an exception when one tries to sort a lookup field (and all kinds of non-data fields) because it is not possible to sort this field with many DB engines. To prevent this exception from raising and warn your users, you can put the following code (C++) in the OnCheckButton event:

   if ((Field->DataType == ftMemo)
   || ((Field->FieldKind != fkData) && (Field->FieldKind != fkInternalCalc)))
      Enabled = false;

obones (administrator)
2004-10-07 11:30

Please test the latest version of the JvDBUltimGrid.pas file from CVS. Fred provided a fix for this.
obones (administrator)
2005-04-01 05:51

No feedback has been provided, this issue is assumed to be fixed.

- Issue History
Date Modified Username Field Change
2004-08-26 02:43 davalv New Issue
2004-08-26 02:51 davalv Note Added: 0005095
2004-08-26 03:06 davalv Note Added: 0005096
2004-09-09 02:03 anonymous Note Added: 0005206
2004-09-09 07:15 davalv Note Added: 0005208
2004-09-09 08:32 anonymous Note Added: 0005210
2004-10-07 11:30 obones Note Added: 0005342
2004-10-07 11:30 obones Status new => feedback
2005-04-01 05:51 obones Status feedback => resolved
2005-04-01 05:51 obones Fixed in Version => 3.00
2005-04-01 05:51 obones Resolution open => fixed
2005-04-01 05:51 obones Assigned To => obones
2005-04-01 05:51 obones Note Added: 0006807

Mantis 1.1.6[^]
Copyright © 2000 - 2008 Mantis Group
Powered by Mantis Bugtracker