StringGrid live update when moving horizontal scrollbar?

In Delphi 2010, I need to display a grid with a horizontal scrollbar with about 15 columns x 5 rows.

I decided to use StringGrid.

However, when the mouse button is not pressed by dragging the horizontal scroll bar, I want the grid to scroll in real time .

The StringGrid component doesn't seem to scroll in real time. It waits until the mouse button is released before updating the column and scrolling, if necessary.

Also, the horizontal scrollbar button (this is what she called) is not proportional to the number of columns. And for the down arrow, when the bottom row moves to the top of the next column to the right ...

This seems like common needs, so I was surprised to not find them in TStringGrid.

Any suggestions on how to solve these two problems? I can use DbGrid or another standard component, but I prefer not to use a commercial grid if I can avoid it. And I'm not going to use shareware or freeware ...

TIA

+3
source share
3 answers

For the first question, you can set goThumbTrackingto StringGrid Optionsat design time or at run time:

StringGrid1.Options := StringGrid1.Options + [goThumbTracking];


On the third question, you can provide the necessary functionality using the keyboard event handlers of the control. Example:

procedure TForm1.StringGrid1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
  StringGrid: TStringGrid;
begin
  StringGrid := Sender as TStringGrid;
  case Key of
    VK_DOWN:
      if StringGrid.Row = StringGrid.RowCount - 1 then begin
        Key := 0;
        StringGrid.Row := StringGrid.FixedRows;
        if StringGrid.Col = StringGrid.ColCount - 1 then
          StringGrid.Col := StringGrid.FixedCols
        else
          StringGrid.Col := StringGrid.Col + 1;
      end;
    VK_UP:    //...;
    VK_RIGHT: //;
    VK_LEFT:  //;
  end;
end;


, , TCustomGrid. , .

+3

, - Freeware, , , . ! . - , .

TStringGrid ( - )

TVirtualStringTree. TStrignGrid. , .

, OnScroll, OnShowScrollbar

http://www.delphi-gems.com/index.php?option=com_content&task=view&id=12&Itemid=38

stackoverflow, tvirtualstringtree

+3

Secondly, the proposal to use TVirtualStringTree. Working with the TStringGrid component is like stabbing yourself in the stomach with rusty scissors.

0
source

Source: https://habr.com/ru/post/1773352/


All Articles