Solved

DBGrid in D3 question...

Posted on 2002-04-26
4
163 Views
Last Modified: 2010-04-04
Hi expert(s),

My Q's:
1) How to clear the grey line in DBGrid so when it show the data, it just look plain white?
2) Some of my fields are vary in size such as char(50) etc. How could I resize the columns auto/manually?

Sample:
FieldA     | FieldB               |
1     | Banker               |
2     | Student               |

I dont want it to be like above eventhough the FieldB is char(50).. I want it to be like this: (it can be resize)

Sample:
FieldA     | FieldB     |
1     | Banker     |
2     | Student     |

TQ...

iqmedia
0
Comment
Question by:iqmedia
  • 2
  • 2
4 Comments
 
LVL 9

Accepted Solution

by:
ITugay earned 200 total points
Comment Utility
Hi iqmedia,

here is a sample:


procedure TForm1.Table1AfterOpen(DataSet: TDataSet);
var
  Max, W: Integer;
begin
  // remove row and col lines in dbgrid
  DBGrid1.Options := DBGrid1.Options - [dgRowLines, dgColLines];

  // calculate with for column number 1
  Max := 0;
  Table1.DisableControls;
  while not Table1.EOF do
  begin
    W := DBGrid1.Canvas.TextWidth(DBGrid1.Columns[1].Field.DisplayText);
    if W > Max then
      Max := W;
    Table1.Next;
  end;
  DBGrid1.Columns[1].Width := Max + 4;
  Table1.First;
  Table1.EnableControls;
end;
0
 

Author Comment

by:iqmedia
Comment Utility
Hi ITugay,

I found a solution based on your sample code...

procedure Form1.Table1AfterOpen(DataSet: TDataSet);
var
   Max, W, i : integer;
begin
     Max := 0;
     Table1.DisableControls;
     for i := 0 to 5 do // if you have 6 colums fields
     begin
          while not Table1.EOF do
          begin
               W := DBGrid1.Columns[i].Field.DisplayWidth;
               if W > Max then
                  Max := W + 4  // adding 4 char or not will still look good
               else
                   Max := DBGrid1.Columns[i].Width + 4;
               Table1.Next;
          end;
     end;
     Table1.First;
     Table1.EnableControls;
end;

Thanks... I accept your sample code as an answer.

iqmedia
0
 

Author Comment

by:iqmedia
Comment Utility
Thanks again...

iqmedia
0
 
LVL 9

Expert Comment

by:ITugay
Comment Utility
Glad to help you,
thanx for points.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

763 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

13 Experts available now in Live!

Get 1:1 Help Now