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
Solved

DBGrid in D3 question...

Posted on 2002-04-26
4
169 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi XE10, MySQL Query 4 165
Downloading email attachments 2 79
TServerSocket - file via sendbuf or Text via sendtext ? 1 65
Tidtcpserver listening on multiports? 1 35
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…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
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…

860 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