Solved

Linking scrollbars of a TdbGrid and a TStringGrid

Posted on 2006-06-22
3
317 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Intraweb download file link ? 1 132
delphi parse string to params 3 122
Controlled Assessment GCSE - desperate help needed 4 84
how to change, disabled button color FMX ? 1 32
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

785 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