Solved

DBGrid in D3 question...

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
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…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 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

26 Experts available now in Live!

Get 1:1 Help Now