Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > DB-Aware

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 03-11-2008, 03:38 AM
rmmario rmmario is offline
Junior Member
 
Join Date: Mar 2008
Posts: 18
Default listbox over dbgrid's column

i intend to show a listbox exactly over (in front of) a specific column of a dbgrid, when i click the dbgrid's title. How can i get the coordinates of the column? like Left and Top or x,y ?

thank you for the help

mario
Reply With Quote
  #2  
Old 03-11-2008, 05:18 AM
Jasser Jasser is offline
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 4,764
Default RE: listbox over dbgrid's column

Try this:

[DELPHI]procedure TForm1.DBGrid1TitleClick(Column: TColumn);
var
i, iLeft : Integer;
begin
DBGrid1.SelectedField := Column.Field;

iLeft := 0;

for i:=0 to Column.Index-1 do
iLeft := iLeft + DBGrid1.Columns[i].Width;

ListBox1.Top := DBGrid1.Top;
ListBox1.Left := iLeft;
ListBox1.Height := DBGrid1.Height;
ListBox1.Width := Column.Width+17;
end;[/DELPHI]

Regards,
Abdulaziz Jasser
Reply With Quote
  #3  
Old 03-11-2008, 05:27 AM
Jasser Jasser is offline
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 4,764
Default RE: listbox over dbgrid's column

A better one:

[DELPHI]procedure TForm1.DBGrid1TitleClick(Column: TColumn);
var
i, iLeft : Integer;
begin
DBGrid1.SelectedField := Column.Field;

iLeft := 6;

for i:=0 to Column.Index-1 do
iLeft := iLeft + DBGrid1.Columns[i].Width;

ListBox1.Top := DBGrid1.Top;
ListBox1.Left := iLeft;
ListBox1.Height := DBGrid1.Height;
ListBox1.Width := Column.Width;

if dgIndicator in DBGrid1.Options then
ListBox1.Width := ListBox1.Width+17;
end;[/DELPHI]

Regards,
Abdulaziz Jasser
Reply With Quote
  #4  
Old 03-11-2008, 05:43 AM
Jasser Jasser is offline
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 4,764
Default RE: listbox over dbgrid's column

A much better one:

[DELPHI]procedure TForm1.DBGrid1TitleClick(Column: TColumn);
var
Rect : TRect;
begin
DBGrid1.SelectedField := Column.Field;

Rect := TStringGrid(DBGrid1).CellRect(Column.Index,1);

ListBox1.Top := Rect.Top;
ListBox1.Left := Rect.Left;
ListBox1.Height := DBGrid1.Height-((Rect.Bottom-Rect.Top)*2)-1;
ListBox1.Width := Rect.Right-Rect.Left+2;
end;[/DELPHI]

Regards,
Abdulaziz Jasser
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:42 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.