Browse Source

Libraries: TVisualGrid bug fix

Herman Schoenfeld 7 years ago
parent
commit
5c8d4a099e
1 changed files with 27 additions and 5 deletions
  1. 27 5
      src/libraries/sphere10/UVisualGrid.pas

+ 27 - 5
src/libraries/sphere10/UVisualGrid.pas

@@ -421,6 +421,7 @@ uses
     property InternalDrawGrid : TDrawGrid read FDrawGrid;
     property InternalDrawGrid : TDrawGrid read FDrawGrid;
     function AddColumn(const AName: utf8string) : TVisualColumn;
     function AddColumn(const AName: utf8string) : TVisualColumn;
     procedure RefreshGrid;
     procedure RefreshGrid;
+    procedure ClearSelection(AIgnoreDeselectionType: boolean = false);
   end;
   end;
 
 
   { TVisualGrid }
   { TVisualGrid }
@@ -1188,6 +1189,7 @@ begin
     Width := 300;
     Width := 300;
     Height := 150;
     Height := 150;
     //Align:=alClient;
     //Align:=alClient;
+    Color:=clWindow;
     Visible:=false;
     Visible:=false;
     AnchorSideLeft.Control := Self;
     AnchorSideLeft.Control := Self;
     AnchorSideLeft.Side := asrCenter;
     AnchorSideLeft.Side := asrCenter;
@@ -1940,6 +1942,8 @@ var
   //LFixedRect: TRect;
   //LFixedRect: TRect;
   LRect: TRect;
   LRect: TRect;
 begin
 begin
+  if ACol > FMultiSearchEdits.Count - 1 then
+    exit;
   LEdit := FMultiSearchEdits[ACol];
   LEdit := FMultiSearchEdits[ACol];
   LEdit.Visible := FDrawGrid.IsFixedCellVisible(aCol, 0);
   LEdit.Visible := FDrawGrid.IsFixedCellVisible(aCol, 0);
   if ACol > 0 then
   if ACol > 0 then
@@ -2363,11 +2367,16 @@ procedure TCustomVisualGrid.SetSelectionType(AValue: TSelectionType);
 begin
 begin
   if FSelectionType=AValue then
   if FSelectionType=AValue then
     Exit;
     Exit;
-
   FSelectionType:=AValue;
   FSelectionType:=AValue;
-  UpdateSelection(FSelectionType);
-
-  GridSelection(Self, 0, 0);
+  // do not select if don't need (otherwise it means false selection event and false selection in grid)
+  if (FDeselectionType = dtNone) or (FLastSelection.Selections <> nil) then
+  begin
+    // reset internal selection variable for stNone (and call event)
+    if FSelectionType = stNone then
+      ResetLastSelection;
+    UpdateSelection(FSelectionType);
+    GridSelection(Self, 0, 0)
+  end;
 end;
 end;
 
 
 procedure TCustomVisualGrid.SetDeselectionType(AValue: TDeselectionType);
 procedure TCustomVisualGrid.SetDeselectionType(AValue: TDeselectionType);
@@ -2381,6 +2390,15 @@ begin
   UpdateSelection(SelectionType);
   UpdateSelection(SelectionType);
 end;
 end;
 
 
+procedure TCustomVisualGrid.ClearSelection(AIgnoreDeselectionType: boolean);
+begin
+  if (FDeselectionType <> dtNone) or AIgnoreDeselectionType then
+  begin
+    ResetLastSelection;
+    UpdateSelection(stNone);
+  end;
+end;
+
 procedure TCustomVisualGrid.SetWidgetControl(AValue: TControl);
 procedure TCustomVisualGrid.SetWidgetControl(AValue: TControl);
 var
 var
   LRefreshPageIndexAndGridInterface: boolean;
   LRefreshPageIndexAndGridInterface: boolean;
@@ -2421,6 +2439,7 @@ var
   LCellData, LRow: Variant;
   LCellData, LRow: Variant;
   LColumn : TVisualColumn;
   LColumn : TVisualColumn;
   LStyle : TTextStyle;
   LStyle : TTextStyle;
+  LDataTable: PDataTable;
 
 
   procedure DrawHeaderCell;
   procedure DrawHeaderCell;
   begin
   begin
@@ -2447,7 +2466,7 @@ var
     if LColumn.HasDataFontStyles then Canvas.Font.Style := LColumn.DataFontStyles;
     if LColumn.HasDataFontStyles then Canvas.Font.Style := LColumn.DataFontStyles;
 
 
     // Get row/cell data
     // Get row/cell data
-    LRow := ActiveDataTable^.Rows[ARow-1];
+    LRow := LDataTable^.Rows[ARow-1];
     LCellData := TDataRowData(LRow)[LColumn.DisplayBinding];
     LCellData := TDataRowData(LRow)[LColumn.DisplayBinding];
 
 
     // Clean data if necessary
     // Clean data if necessary
@@ -2470,6 +2489,9 @@ var
 begin
 begin
   LHandled := False;
   LHandled := False;
   if ColCount = 0 then Exit;
   if ColCount = 0 then Exit;
+  LDataTable := ActiveDataTable;
+  if (ARow > 0) and (ARow > Length(LDataTable^.Rows)) then
+    Exit;
   if ARow = 0 then ResizeSearchEdit(ACol);
   if ARow = 0 then ResizeSearchEdit(ACol);
   LColumn := FColumns[ACol];
   LColumn := FColumns[ACol];
   Rect := CalculateCellContentRect(Rect);
   Rect := CalculateCellContentRect(Rect);