Solved

Lock the first column of a DBGrid?

Posted on 1997-06-24
5
358 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
  • 3
  • 2
5 Comments
 

Accepted Solution

by:
OzBod earned 100 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Secure Boot on W8 & 8.1 8 44
Firewall issues 6 85
How to convert wav to mp3 in delphi 9 137
add combobox item based on numbers 9 98
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…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

708 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now