Solved

Linking scrollbars of a TdbGrid and a TStringGrid

Posted on 2006-06-22
3
311 Views
Last Modified: 2010-04-05
Hi,

I am currently working on a VCL .NET project using Delphi 2006.

I have a form with a TStringGrid and a TdbGrid.

When one of the grids scrolls horizontally (either using the horizontal scroll bar of the user scrolling between cells resulting in the displayed columns shifting), I want the other grid to also scroll by the same number of columns.

I have sample code that works in a Win32 environment by typecasting the dbgrid and then using the 'leftcol' property and reading or setting this based on the tstringgrid's leftcol property. This code doesn't however seem to work in a .NET environment.

When I use the Win32 code in .NET, depending on what I am trying to typecast as, I get one of the following errors:

"invalid typecast";

"Project Project1.exe raised exception class System.NullReferenceException with message 'Object reference not set to an instance of an object.'."

"[Pascal Error] Unit1.pas(810): E2363 Only methods of descendant types may access protected member [Borland.Vcl]TCustomGrid.LeftCol across assembly boundaries"

Any help (that doesn't involve 3rd party components) would be greatly appreciated

Thanks

The sample code I am using for a Win32 environment is below...

TTestDBGrid = class(TDBGrid); //also tried TCustomdbGrid and TCustomGrid

  TForm1 = class(TForm)
    DBGrid1: TDBGrid;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  LC: Integer;
begin
  LC := TTestDBGrid(DBGrid1).LeftCol;
  Inc(LC);
  TTestDBGrid(DBGrid1).LeftCol := LC;
end;
0
Comment
Question by:pagstur
3 Comments
 
LVL 17

Accepted Solution

by:
TheRealLoki earned 125 total points
ID: 16966941
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This video discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now