View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0002096 | JEDI VCL | 00 JVCL Components | public | 2004-08-26 02:43 | 2005-04-01 05:51 |
Reporter | davalv | Assigned To | obones | ||
Priority | normal | Severity | major | Reproducibility | always |
Status | resolved | Resolution | fixed | ||
Product Version | |||||
Target Version | Fixed in Version | 3.00 | |||
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); begin BarcheDBGrid.SortedField:= Column.FieldName; if Main_DataModule.BarcheADOTable.Sort = BarcheDBGrid.SortedField + ' ASC' then begin try Main_DataModule.BarcheADOTable.Sort:= BarcheDBGrid.SortedField + ' DESC'; except end; BarcheDBGrid.SortMarker:= smDown; end else begin try Main_DataModule.BarcheADOTable.Sort:= BarcheDBGrid.SortedField + ' ASC'; except end; BarcheDBGrid.SortMarker:= smUp; end; end; | ||||
Tags | No tags attached. | ||||
|
The exception is launched in JvDBGrid unit in this function: procedure TJvDBGrid.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var Cell: TGridCoord; ACol: Longint; DoClick: Boolean; begin Cell := MouseCoord(X, Y); if FTracking and (FPressedCol <> nil) then begin DoClick := PtInRect(Rect(0, 0, ClientWidth, ClientHeight), {Types.} Point(X, Y)) and (Cell.Y < TitleOffset) and (FPressedCol = GetMasterColumn(Cell.X, Cell.Y)); StopTracking; if DoClick then begin ACol := Cell.X; if dgIndicator in Options then Dec(ACol); if (DataLink <> nil) and DataLink.Active and (ACol >= 0) and (ACol < Columns.Count) then DoTitleClick(FPressedCol.Index, FPressedCol.Field); end; end else if FSwapButtons then begin FSwapButtons := False; MouseCapture := False; if Button = mbRight then Button := mbLeft; end; // Polaris if (Button = mbLeft) and (FGridState = gsColSizing) and (FSizingIndex + Byte(not (dgIndicator in Options)) <= FixedCols) then // and not AutoSizeColumns begin ColWidths[FSizingIndex] := GetMinColWidth(X - FSizingOfs - CellRect(FSizingIndex, 0).Left); FGridState := gsNormal; // Exit; end; // 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 DoAutoSizeColumns; end; |
|
This is a better code: procedure TForm_Barche.BarcheDBGridTitleClick(Column: TColumn); begin 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; end else begin TADOTable(BarcheDBGrid.DataSource.DataSet).Sort:= BarcheDBGrid.SortedField + ' ASC'; BarcheDBGrid.SortMarker:= smUp; end; end; |
|
You cannot sort this kind of field. This is not a DBGrid limitation but an ADO one (try to sort with ORDER BY instead). |
|
I suggest to use this simple code to prevent exceptions: //--------- if Column.Field.FieldKind = fkLookup then Exit; //--------- |
|
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))) { Sysutils::Beep; Enabled = false; } Fred |
|
Please test the latest version of the JvDBUltimGrid.pas file from CVS. Fred provided a fix for this. |
|
No feedback has been provided, this issue is assumed to be fixed. |
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 |