Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

DBGrid in D3 question...

Posted on 2002-04-26
4
Medium Priority
?
175 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
[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
  • 2
  • 2
4 Comments
 
LVL 9

Accepted Solution

by:
ITugay earned 600 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

Independent Software Vendors: 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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

597 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