Solved

Linking scrollbars of a TdbGrid and a TStringGrid

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Making delphi communicate with a c# service 16 112
SUM 2 INTEGER ARRAYS INTO 1 10 108
Wincontrol not (correctly) drawn 15 42
shape, triangle, dbctrlgrid 3 17
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

830 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