Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help adding Tbutton to DBGrid please

Status
Not open for further replies.

BuilderSpec

Programmer
Dec 24, 2003
383
GB
Hi

Hoping someone can help.

Using C++ builder 6

New Project , add a TButton called Button1 , a DBGrid and associate some data to it. Mine has at least 3 columns of data.

Want the end result to be that in the 3rd column I want a button to display.

I have got this so far :

void __fastcall TForm1::DBGrid1DrawColumnCell(TObject *Sender,
const TRect &Rect, int DataCol, TColumn *Column,
TGridDrawState State)
{


if ( Button1->Parent != DBGrid1 )
Button1->Parent = DBGrid1;

if ( Column->Index == 2 )
{
if ( State.Contains(gdFocused) )
{
if ( Button1->Left != (Rect.Right - Button1->Width ) )
Button1->Left = Rect.Right - Button1->Width ;
if ( Button1->Top != Rect.Top )
Button1->Top = Rect.Top;
if ( Button1->Height != ( Rect.Bottom - Rect.Top ) )
Button1->Height = Rect.Bottom - Rect.Top ;
Button1->Visible = true;
}
}
}


Only issue is that it only shows the button if I am on that record and would like it to show the button on all records. The above only shows the button per line if i click into column 3. Would like the button to show regardless if possible for all rows. But at the least to show button when i enter the record regardless of column.

Any ideas please ?

Graham

Hope this helps!

Regards

BuilderSpec
 
I'm not certain but maybe this article will help.


James P. Cottingham
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
Good day, Graham

I didn't fully understand your question. Do you want to show this button in all your records in column 3 simultaneously? Or do you simply want this button to be shown in column 3 regardless of the column you chose?

The first variant seems to me impossible, because I can't understand, how one object can be placed in many cells simultaneously. And if you want the second variant, you simply can change your code of DBGrid1DrawColumnCell() function to this one:

if ( Button1->Parent != DBGrid1 )
Button1->Parent = DBGrid1;
if ( State.Contains(gdFocused) ) {
int leftB = DBGrid1->Columns->Items[0]->Width + DBGrid1->Columns->Items[1]->Width + DBGrid1->Columns->Items[2]->Width + 15;
if ( Button1->Left != leftB - Button1->Width )
Button1->Left = leftB - Button1->Width ;
if ( Button1->Top != Rect.Top )
Button1->Top = Rect.Top;
if ( Button1->Height != ( Rect.Bottom - Rect.Top ) )
Button1->Height = Rect.Bottom - Rect.Top ;
Button1->Visible = true;
}

Or maybe I just didn't understand you correctly :)

Hope, it will help you

Vadim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top