if not Assigned(Field) or not FieldIsMapped(Field) then Free; I := FDataLink.FieldCount; if (I = 0) and (FColumns.Count = 0) then Inc(I); for J := 0 to I-1 do begin Fld := FDatalink.Fields[J]; if Assigned(Fld) then begin K := J; { Pointer compare is valid here because the grid sets matching column.field properties to nil in response to field object free notifications. Closing a dataset that has only default field objects will destroy all the fields and set associated column.field props to nil. } while (K < FColumns.Count) and (FColumns[K].Field <> Fld) do Inc(K); if K < FColumns.Count then Column := FColumns[K] else begin Column := TPassthroughColumn.Create(FColumns); Column.Field := Fld; end; end else Column := TPassthroughColumn.Create(FColumns); Column.Index := J; end; end else begin { Force columns to reaquire fields (in case dataset has changed) } for I := 0 to FColumns.Count-1 do FColumns[I].Field := nil; end; if FVertical then begin RowCount := FColumns.Count + FIndicatorOffset; inherited FixedRows := FIndicatorOffset; end else begin ColCount := FColumns.Count + FIndicatorOffset; inherited FixedCols := FIndicatorOffset; end; FTitleOffset := 0; if dgTitles in Options then FTitleOffset := 1; RestoreCanvas := not HandleAllocated; if RestoreCanvas then Canvas.Handle := GetDC(0); try Canvas.Font := Font; K := Canvas.TextHeight(''''Wg'''') + 3; if dgRowLines in Options then Inc(K, GridLineWidth); DefaultRowHeight := K; if dgTitles in Options then begin K := 0; for I := 0 to FColumns.Count-1 do begin Canvas.Font := FColumns[I].Title.Font; J := Canvas.TextHeight(''''Wg'''') + 4; if J > K then K := J; end; if K = 0 then begin Canvas.Font := FTitleFont; K := Canvas.TextHeight(''''Wg'''') + 4; end; if FVertical and (K > DefaultRowHeight) then DefaultRowHeight := K else RowHeights[0] := K; end; finally if RestoreCanvas then begin ReleaseDC(0,Canvas.Handle); Canvas.Handle := 0; end; end; UpdateRowCount; SetColumnAttributes; UpdateActive; Invalidate; end;
procedure TCustomVDBGrid.LayoutChanged; begin if FColumns.Count > 0 then if FVertical then RowCount := FColumns.Count + FIndicatorOffset else ColCount := FColumns.Count + FIndicatorOffset; if AcquireLayoutLock then EndLayout; end;
procedure TCustomVDBGrid.LinkActive(Value: Boolean); begin if not Value then HideEditor; FBookmarks.LinkActive(Value); LayoutChanged; UpdateScrollBar; if Value and (dgAlwaysShowEditor in Options) then ShowEditor; end;
procedure TCustomVDBGrid.Loaded; begin inherited Loaded; LayoutChanged; end;
procedure TCustomVDBGrid.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var Cell: TGridCoord; OldCol,OldRow: Integer; begin if not AcquireFocus then Exit; if (ssDouble in Shift) and (Button = mbLeft) then begin DblClick; Exit; end; if Sizing(X, Y) then begin FDatalink.UpdateData; inherited MouseDown(Button, Shift, X, Y) end else begin Cell := MouseCoord(X, Y); if ((csDesigning in ComponentState) or (dgColumnResize in Options)) and (IIF(FVertical, Cell.X, Cell.Y) < FTitleOffset) then begin FDataLink.UpdateData; inherited MouseDown(Button, Shift, X, Y) end else if FDatalink.Active then with Cell do begin BeginUpdate; { eliminates highlight flicker when selection moves } try HideEditor; OldCol := Col; OldRow := Row; if (IIF(FVertical, X, Y) >= FTitleOffset) and (IIF(FVertical, X - Col, Y - Row) <> 0) then FDatalink.Dataset.MoveBy(IIF(FVertical, X - Col, Y - Row)); if IIF(FVertical, Y, X) >= FIndicatorOffset then MoveCol(IIF(FVertical ,Y, X)); if (dgMultiSelect in Options) and FDatalink.Active then with FBookmarks do begin FSelecting := False; if ssCtrl in Shift then CurrentRowSelected := not CurrentRowSelected else begin Clear; CurrentRowSelected := True; end; end; if (Button = mbLeft) and (((X = OldCol) and (Y = OldRow)) or (dgAlwaysShowEditor in Options)) then ShowEditor { put grid in edit mode } else InvalidateEditor; { draw editor, if needed } finally EndUpdate; end; end; end << 上一页 [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] 下一页 |