how to avoid grid resizing ?

Hi All,

I have a small grid, 4-5 visual lines, to which I will add rows as input is being entered in fields, and records are updated in the database. I want to use the small grid to show a subset of the data entered and the 4-5 last records added.

How can I:
1. Avoid that the grid height changes as I add rows ? I want to stay with the fixed height as when I was designed. I have put the to ssAuto.

2. How do I make sure that the last row is always visible ? I mean, if there is 16 rows currently added to the grid, and only room for 4 to be visible, I will want my top row in the grid to be number 14. How can I do that ?

With a combination of Controller,position and .indicatortype, and Rowcount, TotalRows and ActveRow, I have a working solution. It implies a visible header with paging and priv/next and the page with the activerow show, meaning when ever I add a row, I change Activerow and if necessary, the page is changed so that ActiveRow is visible.

It is not quite what I want, which is more like the behavior of a listbox: ,one long list of rows, with a vertical scrollbar, and a function to set the top visible row.

Are there any such possibilities with the AdvWebGrid ?


You can enable vertical scrolling by setting UseFullHeight to True. If Scroll.ScrollIntoView is True the grid should automatically scroll to display the active row.
Hi Bart,

I'm sorry but don't seem to be able to make it work.

I do not get any vertical scrollbar if I set UseFullHeight. If I set Rowcount to say 10, it will change page when I add row 11, regardless of how the settings of the controller is. With no page controls set in the header (with position = none, indicatorttype = none, pagetype = none) it do not show the header, but still segment the grid into pages. Rowcount being the page size.

If I set rowcount to zero, and add one to totalrows for every insert, the size of the grid will grow and grow for each insert, even beyond the bottom of the size of the designed grid, and further down endlessly. No vertical Scrollbar and no stop within the borders of the grid.

Do you have an example of a grid with a vertical scrollbar ?

NB! I'm talking about the normal advwebgrid, not thw dbware advwebgrid.


Example to demonstrate the grid vertical scrolling: 

Place a new TTIWAdvWebGrid on the form and set the following properties: 

procedure TIWForm1.IWAppFormCreate(Sender: TObject);
  TIWAdvWebGrid1.RowCount := 100;
  TIWAdvWebGrid1.UseFullHeight := True;
  TIWAdvWebGrid1.Scroll.Style := scAuto;

Follow up and correction: By setting UseFullHeight and to ssAuto, I get the grid to stay within the designed height, and get the vertical scrollbar once I add a row below the visual size.
When adding a row, I also set ActiveRow to the same rownumber as the new row, but regardless of the setting of ScrollIntoView, my visual grid only show the first 10 added rows. No scrolling to activeRow. What am I missing ?

NB! I using an OnClick event of a button to add new rows, so it is with a full refresh for every new row.


Thanks. I did not see your reply until I posted my follow up but as you can see, I've done almost at you propose. Only difference is RowCount is set to zero in my example.

I finally got it:
Using a RowCount of 100 will set a page size of one hundred rows and once I add row 101, it changes to next page.
However, with these settings I've managed to get it to work as I want to (thanks to your help):

ActiveRow = 0
RowCount = 0
TotalRows = 0
UseFullHeight = yes
Scroll.ScrollIntoView = yes
Scroll.stype = ssAuto
Width and Height to show 3 columns in 10 rows (default)

and in the button.OnClick event I add a row like this

TIWAdvWebGrid1.RowCount := TIWAdvWebGrid1.RowCount + 1;
TIWAdvWebGrid1.ActiveRow := TIWAdvWebGrid1.RowCount - 1;

And add contents to the cells with

TIWAdvWebGrid1.Cells[0,TIWAdvWebGrid1.ActiveRow] := TIWAdvWebGrid1.ActiveRow.ToString;
TIWAdvWebGrid1.Cells[1,TIWAdvWebGrid1.ActiveRow] := DateToStr(now);
TIWAdvWebGrid1.Cells[2,TIWAdvWebGrid1.ActiveRow] := TimeToStr(now);

Again, thanks for your help.

Thank you for confirming the issue was resolved.