Insert Row in TAdvStringGrid

I have a TAdvStringGrid containing Data and i would like to insert single or multiple Rows into that grid.
Somehow i don't get usable result Grid.InsertRows.
Do you have eventually a example showing how to insert rows and fill them with Data.
Thanks in Advance

Grid.InsertRows should do this. What exact problem do you have with using this?

Thanks for answering,

  • My grid is sorted by column 1
  • I get a list of entries to add to the grid. This should replace (Update) the already available rows entries
  • I set a filter on that column and check how many rows corresponds to my filter
  • If the new entry list is bigger than the filtered rows I add insert the missing rows
  • Then I add all the new entries
  • I clear the filter and the added row are always at the end and not in the order according to the sort of col 1

I already realized that after filtering row index depends of the filtered means if 3 rows are filtered the index will be 1 to 3.
The code I use is quite simple.

// Check assignemnment for Date
grdAssignedShift.FilterActive:= False;
with grdAssignedShift.Filter.Add do
Condition := sDate;
Column := 1;
Operation := foNONE;
grdAssignedShift.FilterActive:= True;

iRowCount:= grdAssignedShift.RowCount - 1;
// Insert Line if requiered
if iRowCount < slSelectedUsers.Count then
iRowToAdd:= slSelectedUsers.Count - iRowCount;
for i := 1 to iRowToAdd do
grdAssignedShift.InsertRows(i + 1,1);
grdAssignedShift.Cells[1,i + 1] := sDate;
grdAssignedShift.Cells[2,i + 1] := sDay;
// at this point i will the update all value from slSelectedUsers
// to one of the other column
// For i....
// grdAssignedShift.Cells[1,i + 1] := slSelectedUsers[i];

grdAssignedShift.FilterActive:= False;

Hope this explains what I try to do.
In fact it works except the grid is not sorted correctly
Thanks and regards

Try setting grid.FilterType = ftSuppress and then you do not need to take row index changes due to filtering in account

Thanks Bruno for our help,
In fact the only ting I had to add was grdAssignedShift.Sort(1); after inserting some record.
This issue is solved for my program.
Next will be Grouping and Regrouping after adding records.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.