FAIL : Filter makes me crazy :-S

Hi again.


Using filter to show only a subset of rows in a tadvstringgrid has some serious flaws.
Being able to use insert to - well insert - a row at a given index/position in the grid ... will not work correctly when using filters. The inserted row can appear at any index in the current filter - and not at the position specified.

Is there an example of Master / Detail using filter - that works?

Kind Regards.
Bjarne Rasmussen

row insertion in a grid that is filtered is indeed not supported, please set FilterActive = false, insert the row and then set FilterActive = true again.
Wrt master/detail, in what way do you implement master/detail now in TAdvStringGrid?

Hi.

Thx for suggesting that I should disable filtering when inserting.
But thats just not good enough.

My master/detail could best be described as an Order / OrderLine coupling.
In Grid1 you select an Order (Row) - and Grid2 filters on column 1 "=10001" (just an example).

I know this is not the best solution - but I had the idea that the grid should provide the means to do it.
Grid2 could potentially explode (massive amount of rows) - but in my app. we are talking about 10-30 rows.

Try setting it up - play with it ... and you will see that it will break when using INS to add records in grid2.

I've tried disabling the filter before inserting - and that is doable. But I end up with a grid that is unfiltered.
Since I cannot allow the filter to be active before the record is inserted. That is .. the user will see a lot of "garbage" data when inserting.

How can I show ONLY the filtered records - while inserting ?

Best solution I've found is :


DISABLE "AllowInsertRow" - Insert key will not be captured by grid.
Now we will have manual control over the insert procedure.

Set the OnKeyDown event to something like this.

procedure TForm1.AdvStringGrid1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
var
  RR : Integer;
  boousefilter : boolean;
begin
  if Key = VK_INSERT then
  begin
    boousefilter := AdvStringGrid1.FilterActive;
    RR := AdvStringGrid1.GetRealRow;  // Do this BEFORE disabling the filter ..... IMPORTANT !!!
    if boousefilter then
      AdvStringGrid1.FilterActive := false;

    AdvStringGrid1.InsertRows(RR,1);
    AdvStringGrid1.Ints[0,RR] := 2;    // filter value
    AdvStringGrid1.Ints[3,RR] := RR;

    if boousefilter then
      AdvStringGrid1.FilterActive := true; // Omitting to enable filter (if disabled) will insert at corret pos - but selected cell will be incorrect.
  end;
end;

And Voila - Pressing INSERT on a Filtered grid now works as intended.

Other suggestions and any good advice are more than welcome - since I'm only just getting started with this grid and already find myself banging my head into the wall. I really think that this should be handled by the grid pr standard.

The issue is that to implement this in an automatic way, it must be ensured that the inserted row always satisfies the filter condition, otherwise, the behavior would not be logical. We'll look to implement the needed functionality in the grid itself, but it will be required to preset data of the new inserted row from the OnAutoInsertRow event in such way that it meets the filter condition.

Hi Bruno.


You're absolutely correct about that.
But it could be done by making it possible to "link" grids. 
Grid1 (Key columns) 
Grid2 (FKey columns)
Basically like a Relational DB. This way it would be possible to visually (if editor was made - plz do :-) ) link grids and have easy control over filtering. 

Just a suggestion to improve this grid :-)

Maybe this sample 
http://www.tmssoftware.com/site/asg57.asp is helpful?

Nice example Bruno.

Grids in grids ... good combo :-)
Could be cool if you did not have to specify the editor manually - but via a grid design editor / layout manager could specify editor for cells/rows/cols, layout for ditto and perhaps grid link capabilities :-)
And that way totally get rid of alle the manual stuff ...