?
Solved

Lock the first column of a DBGrid?

Posted on 1997-06-24
5
Medium Priority
?
372 Views
Last Modified: 2010-04-04
I am trying to lock the first column of a DBGrid so that when the user scrolls to the right, the first column will stay in view.  Is there an easy way to do this without writing a new component?  If you can help, I'd appreciate it.

Thanks,
Scott
0
Comment
Question by:millerw
[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
  • 2
5 Comments
 

Accepted Solution

by:
OzBod earned 400 total points
ID: 1337700
The easiest way to solve your problem is to make a descendant of TDBGrid which gives access to the FixedCols property. This is a simple one line adjustment in the descended Grid as shown below :


unit Mydbgrid;

interface

uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,Forms, Dialogs, Grids,DBGrids,DB,DBTables;

type
  TMYDBGRID = class(TDBGrid)
  private
    { Private declarations }

  protected
    { Protected declarations }

  public
    { Public declarations }

    property FixedCols;   {this is the only change needed}


  published
    { Published declarations }
   


  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('DBControls', [TMYDBGRID]);
end;


end.


I would recommend creating a descendant, initially starting with the FixedCols property. This will form a kickstart to making other modifications down the line to compensate for some of the shortfalls in TDBGrid that you will invariably come across with further exposure.

Note : Do not include the FixedCols property in the published section. This temptation to be able to set FixedCols at design time comes unstuck if at runtime the Table attached to the Grid is not opened. This results in an error message which states that 'FixedCols greater than total columns' or something to that effect. If you programmatically set FixedCols after you are sure the Table is opened then this will not cause a problem
0
 
LVL 1

Author Comment

by:millerw
ID: 1337701
Thanks.  It does work.  I finally figured out that the FixedCols must be set to the value of the column AFTER the column you want to make fixed.  Other than that little missing information your explaination was excellent.  

Thanks again,
Scott
0
 

Expert Comment

by:OzBod
ID: 1337702
Not quite sure what you meant by setting the value of the column after the column you want fixed ??? Did you allow for the cloumn that shows the position indicator, which would be column 0

Anyway, glad it was of use
0
 
LVL 1

Author Comment

by:millerw
ID: 1337703
Yes I took it into consideration.  What I meant is I was trying to set the value to 1 for my first column so that it would remain fixed.  That didn't work, so I tried 0 and that told me "Index out of Range."  Having nothing else to try but a bigger number, I tried 2 and that made the columns 2 on NOT fixed and the columns under 2 FIXED (e.g. my first column and the position indicator).  That is the only catch to using what you told me.  It only took me about 10 min with all the compiling, testing, and exception handling to figure it out.

Thanks once again.

BTW, mind if I call on you sometime for help later?  I am writing my first database program in Delphi and the docs suck when it comes to database stuff.  I've had no problems with other stuff but the database if giving me problems.  Do you have any hints/books/suggestions on where i can find come good information or what to watch out for in database progamming?  One last thing, do you have any data-aware components that you have written so that I can look at how you did it?  I have read the book but I'm still not sure if I have all the information I need.

Talk to you later,
Scott
0
 

Expert Comment

by:OzBod
ID: 1337704
Sure, contact me anytime. I can't 'guarantee' that I can answer all your questions but certainly will if I can. I should mention that I almost exclusively use dBase files for a variety of reasons and have skipped using BDE by buying Apollo by Successware. As an ex-Clipper programmer using dBase files I find Apollo shortcuts all my problems with databases and has some lovely little features that save me a stack of time in re-programming.

I've always had difficulty finding a good source that deals with database programming, unless you are using Clent/Server. One book I can recommend for topics that cover a wide range and is extremely useful is Niel Rubenking's "Delphi - Programming Problem Solver". Also suggest you check out the Freeware rxLib component collection which can be found at Delphi Super Page. Some lovely ones useful for DBAware components.

As for my own, they are a mix-mash of ideas from various sources which solve my immediate problems at the time. I am reticent to release them as I cannot guarantee them working on different development setups.

Anyway, keep on Delphi-ing... the final result is worth the effort.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

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