TAdvStringGrid
Example 79 : Adding scrollbars on grid cells
When text is too large to fit in a cell, you could increase the cell size, ie. increase the row height, the column width or both. This is not always practical, as the higher the row height is, the less rows can be displayed. The same applies for the column width. The text could also be displayed cut-off but this solution is also far from ideal. Now, an alternative solution is available with the capability to add a vertical scrollbar to a cell. Any cell can as such have its own scrollbar and scroll separately the cell's text or HTML formatted text. This feature is made available with the grid.AddScrollbar() method. With this method a scrollbar is added to a cell. The scrollbar range and pagesize can either be automatically set according to the size of the text in a cell or can be programmatically set.This is an overview of the methods available:
grid.AddScrollbar(col,row: integer; AutoRange: boolean); | Adds a scrollbar to cell col,row and when AutoRange is true, the scrollbar range and pagesize is automatically calculated. |
grid.RemoveScrollbar(col,row: integer); | Removes the scrollbar again from the cell |
grid.HasScrollBar(col,row: integer): boolean | Returns true when the cell col,row has a scrollbar |
grid.HasAutoRangeScrollBar(col,row: integer): boolean | Returns true when the cell col,row has an autorange scrollbar |
grid.SetScrollPosition(col,row,position: integer); | Programmatically sets the position of the scrollbar in cell col,row |
grid.GetScrollPosition(col,row,position: integer): integer; | Programmatically gets the position of the scrollbar in cell col,row |
grid.SetScrollProp(col,row: integer; Prop: TScrollProp); | Sets the scrollbar range & pagesize |
grid.GetScrollProp(col,row: integer): TScrollProp; | Gets the scrollbar range & pagesize |
Delphi project & source files for downloading included in the main demos distribution for Delphi
In the sample, these capabilities are demonstrated by adding very long HTML formatted text in 3 cells of the grid. In these cells, first an autorange scrollbar was added with:
advstringgrid1.AddScrollBar(2,1,true); advstringgrid1.AddScrollBar(2,2,true); advstringgrid1.AddScrollBar(2,3,true);
procedure TForm2.AdvStringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer; var CanSelect: Boolean); var sp: TScrollProp; begin if AdvStringgrid1.HasScrollBar(Acol,ARow) then begin sp := AdvStringgrid1.GetScrollProp(ACol,ARow); updown1.Min := 0; updown1.Max := sp.Range; updown1.Position := sp.Range - AdvStringgrid1.GetScrollPosition(ACol,ARow); end; end; procedure TForm2.UpDown1Changing(Sender: TObject; var AllowChange: Boolean); var sp: TScrollProp; begin if AdvStringGrid1.HasScrollBar(AdvStringgrid1.Col, AdvStringGrid1.Row) then begin AdvStringGrid1.SetScrollPosition(AdvStringgrid1.Col, AdvStringGrid1.Row, updown1.Max - updown1.Position); end; end;
Delphi project & source files for downloading included in the main demos distribution for Delphi
×