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?
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 :-)
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 ...