Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Linking scrollbars of a TdbGrid and a TStringGrid

Posted on 2006-06-22
3
Medium Priority
?
325 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 500 total points
ID: 16966941
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

721 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