Solved

DBGrid in D3 question...

Posted on 2002-04-26
4
166 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
ID: 6970770
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
ID: 6972784
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
ID: 6972787
Thanks again...

iqmedia
0
 
LVL 9

Expert Comment

by:ITugay
ID: 6972900
Glad to help you,
thanx for points.
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Correct Component for Shopping Cart. 2 105
SUM 2 INTEGER ARRAYS INTO 1 10 100
update joined tables 2 46
Tvertscrollbox like a whatsapp layout 5 28
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…
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

810 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