打印本文 打印本文 关闭窗口 关闭窗口
让你的DBGrid竖着站(1)
作者:武汉SEO闵涛  文章来源:敏韬网  点击数12236  更新时间:2009/4/23 18:28:26  文章录入:mintao  责任编辑:mintao
ion ReadOnlyField(Field: TField): Boolean;
var
  MasterField: TField;
begin
  Result := Field.ReadOnly;
  if not Result and (Field.FieldKind = fkLookup) then
  begin
    Result := True;
    if Field.DataSet = nil then Exit;
    MasterField := Field.Dataset.FindField(Field.KeyFields);
    if MasterField = nil then Exit;
    Result := MasterField.ReadOnly;
  end;
end;

procedure TCustomVDBGrid.SetColumnAttributes;
var
  I: Integer;
begin
   if not FVertical then
      for I := 0 to FColumns.Count-1 do
      with FColumns[I] do
        begin
        TabStops[I + FIndicatorOffset] := not ReadOnly and DataLink.Active and
        Assigned(Field) and not (Field.FieldKind = fkCalculated) and not ReadOnlyField(Field);
        ColWidths[I + FIndicatorOffset] := Width;
        end;
   if (dgIndicator in Options) then
     ColWidths[0] := IIF(FVertical, TitlesWidth, IndicatorWidth);
end;


function TCustomVDBGrid.TabStopRow(Arow: integer): Boolean;
var DataCol: integer;
begin
  Result := False;
  DataCol := RawToDataColumn(ARow);
  if (DataCol >= 0) and (DataCol < FColumns.Count) then
    with FColumns[DataCol] do
     Result := not ReadOnly and DataLink.Active and
     Assigned(Field) and not (Field.FieldKind = fkCalculated) and not ReadOnlyField(Field);
end;


procedure TCustomVDBGrid.SetDataSource(Value: TDataSource);
begin
  if Value = FDatalink.Datasource then Exit;
  FBookmarks.Clear;
  FDataLink.DataSource := Value;
  if Value <> nil then Value.FreeNotification(Self);
  LinkActive(FDataLink.Active);
end;

procedure TCustomVDBGrid.SetEditText(ACol, ARow: Longint; const Value: string);
begin
  FEditText := Value;
end;

procedure TCustomVDBGrid.SetOptions(Value: TDBGridOptions);
const
  LayoutOptions = [dgEditing, dgAlwaysShowEditor, dgTitles, dgIndicator,
    dgColLines, dgRowLines, dgRowSelect, dgAlwaysShowSelection];
var
  NewGridOptions: TGridOptions;
  ChangedOptions: TDBGridOptions;
begin
  if FOptions <> Value then
  begin
    NewGridOptions := [];
    if dgColLines in Value then
      NewGridOptions := NewGridOptions + [goFixedVertLine, goVertLine];
    if dgRowLines in Value then
      NewGridOptions := NewGridOptions + [goFixedHorzLine, goHorzLine];
    if dgColumnResize in Value then
      if FVertical then
         NewGridOptions := NewGridOptions + [goColSizing, goRowMoving]
      else
         NewGridOptions := NewGridOptions + [goColSizing, goColMoving];
    if dgTabs in Value then Include(NewGridOptions, goTabs);
    if dgRowSelect in Value then
    begin
      Include(NewGridOptions, goRowSelect);
      Exclude(Value, dgAlwaysShowEditor);
      Exclude(Value, dgEditing);
    end;
    if dgEditing in Value then Include(NewGridOptions, goEditing);
    if dgAlwaysShowEditor in Value then Include(NewGridOptions, goAlwaysShowEditor);
    inherited Options := NewGridOptions;
    if dgMultiSelect in (FOptions - Value) then FBookmarks.Clear;
    ChangedOptions := (FOptions + Value) - (FOptions * Value);
    FOptions := Value;
    if ChangedOptions * LayoutOptions <> [] then LayoutChanged;
  end;
end;

procedure TCustomVDBGrid.SetSelectedField(Value: TField);
var
  I: Integer;
begin
  if Value = nil then Exit;
  for I := 0 to Columns.Count - 1 do
    if Columns[I].Field = Value then
      MoveCol(DataToRawColumn(I));
end;

procedure TCustomVDBGrid.SetSelectedIndex(Value: Integer);
begin
  MoveCol(DataToRawColumn(Value));
end;

procedure TCustomVDBGrid.SetTitleFont(Value: TFont);
begin
  FTitleFont.Assign(Value);
  if dgTitles in Options then LayoutChanged;
end;

function TCustomVDBGrid.StoreColumns: Boolean;
begin
  Result := Columns.State = csCustomized;
end;

procedure TCustomVDBGrid.TimedScroll(Direction: TGridScrollDirection);
begin
  if FDatalink.Active then
  begin
    with FDatalink do
    begin
      if sdUp in Direction then
      begin
        DataSet.MoveBy(-ActiveRecord - 1);
        Exclude(Direction, sdUp);
      end;
      if sdDown in Direction then
      begin
        DataSet.MoveBy(RecordCount - ActiveRecord);
        Exclude(Direction, sdDown);
      end;
    end;
    if Direction <> [] then inherited TimedScroll(Direction);
  end;
end;

procedure TCustomVDBGrid.TitleClick(Column: TColumn);
begin
  if Assigned(FOnTitleClick) then FOnTitleClick(Column);
end;

procedure TCustomVDBGrid.TitleFontChanged(Sender: TObject);
begin
  if (not FSelfChangingTitleFont) and not (csLoading in ComponentState) then
    ParentFont := False;
  if dgTitles in Options then LayoutChanged;
end;

procedure TCustomVDBGrid.UpdateActive;
var
  NewRow: Integer;
  Field: TField;
begin
  if FDatalink.Active and HandleAllocated and not (csLoading in ComponentState) then
  begin
    NewRow := FDatalink.ActiveRecord + FTitleOffset;
    if IIF(FVertical, Col, Row) <> NewRow then
    begin
      if not (dgAlwaysShowEditor in Options) then HideEditor;
      if FVertical then
         MoveColRow(NewRow, Row , False, False)
      else
         MoveColRow(Col, NewRow, False, False);
      InvalidateEditor;
    end;
    Field := SelectedField;
    if Assigned(Field) and (Field.Text <> FEditText) then
      InvalidateEditor;
  end;
end;

procedure TCustomVDBGrid.UpdateData;
var
  Field: TField;
begin
  Field := SelectedField;
  if Assigned(Field) then
    Field.Text := FEditText;
end;

procedure TCustomVDBGrid.UpdateRowCount;
begin
  if FVertical then
     begin
     if ColCount <= FTitleOffset then ColCount := FTitleOffset + 1;
     end
  else
     if RowCount <= FTitleOffset then RowCount := FTitleOffset + 1;
  if FVertical then
     FixedCols := FTitleOffset
  else
     FixedRows := FTitleOffset;
  with FDataLink do
    if not Active or (RecordCount = 0) or not HandleAllocated then
      if FVertical then
         ColCount := 1 + FTitleOffset
      else
         RowCount := 1 + FTitleOffset
    else
    begin
      if FVertical then
         ColCount := IIF(FOnlyOne,1+ FTitleOffset,1000)
      else
         RowCount := IIF(FOnlyOne,1+ FTitleOffset,1000);
      FDataLink.BufferCount := IIF(FVertical, VisibleColCount, VisibleRowCount);
      if FVertical then
         ColCount := IIF(FOnlyOne,1+FTitleOffset,RecordCount + FTitleOffset)
      else
         RowCount := IIF(FOnlyOne,1+FTitleOffset,RecordCount + FTitleOffset);
      if dgRowSelect in Options then
         TopRow := FixedRows;
      UpdateActive;
    end;
end;

procedure TCustomVDBGrid.UpdateScrollBar;
var
  SIOld, SINew: TScrollInfo;
begin
  if FDatalink.Active and HandleAllocated then
    with FDatalink.DataSet do
    begin
      SIOld.cbSize := sizeof(SIOld);
      SIOld.fMask := SIF_ALL;
      if FVertical then
  &n

 << 上一页  [11] [12] [13] [14] [15] [16] [17] [18] [19] [20]  下一页

打印本文 打印本文 关闭窗口 关闭窗口