Solved

Linking scrollbars of a TdbGrid and a TStringGrid

Posted on 2006-06-22
3
323 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 17

Accepted Solution

by:
TheRealLoki earned 125 total points
ID: 16966941
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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
Delphi Form ownership 4 160
Create a path if not exists 7 128
Firemonkey webbrowser scrollbars ? 1 73
How to remove Recent Projects from Embarcadero C++ builder XE10. Berlin 2 93
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…
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…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

752 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