GridLineWidth (C++)
Description
The following code uses the bitmaps in an image list component to draw the contents of each cell in a draw grid. This example includes a draw grid on a form. When the application runs and the form is created, the width of the lines on the draw grid changes if the default column width of the grid is over 90 pixels wide. This example requires a populated image list; otherwise, it displays an empty grid. Set the draw grid DefaultColWidth and GridLineWidth statically to values that cause the button click to start an action.
Code
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if (DrawGrid1->DefaultColWidth > 90)
DrawGrid1->GridLineWidth = 2;
else
DrawGrid1->GridLineWidth = 1;
}
void __fastcall TForm1::DrawGrid1DrawCell(TObject *Sender, int ACol, int ARow, TRect &Rect,
TGridDrawState State)
{
int index = ARow * DrawGrid1->ColCount + ACol;
DrawGrid1->Canvas->Brush->Color = clBackground;
DrawGrid1->Canvas->FillRect(Rect);
ImageList1->Draw(DrawGrid1->Canvas, Rect.Left, Rect.Top, index, True);
if (State.Contains(gdFocused))
{
DrawGrid1->Canvas->DrawFocusRect(Rect);
}
}
void __fastcall TForm1::DrawGrid1SelectCell(TObject *Sender, int ACol, int ARow, bool &CanSelect)
{
CanSelect = True;
}
Uses
- Vcl.Grids.TCustomGrid.DefaultColWidth ( fr | de | ja )
- Vcl.Grids.TCustomGrid.GridLineWidth ( fr | de | ja )