Jump to content


Photo

Moving the (Multiple) Selection


  • Please log in to reply
No replies to this topic

#1 wvd_vegt

wvd_vegt

    Master Member

  • Honorable Members
  • PipPipPipPipPip
  • 710 posts
  • Gender:Male
  • Location:the Netherlands

Posted 18 March 2005 - 10:45 PM

Hi,

Here some code to move a (multiple) selection up or downwards. When the first selected row reaches the top it starts condensing free space in a multiple selection until there is none left. This way the order of rows will not change when reaching the top or bottom.

Upwards:

CODE
procedure TForm1.ToolButton27Click(Sender: TObject);

var

 i, j              : Integer;

begin

 //determine if we can move or condense any further upwards

 for i := 0 to Pred(GridView6.SelectedCount) do

   if not (GridView6.Selected[i]) then

     begin

       for j := i to Pred(GridView6.RowCount) do

         if (GridView6.Selected[j]) then

           GridView6.MoveRow(j, j - 1);

       Break;

     end;

end;


Downwards:

CODE
procedure TForm1.ToolButton28Click(Sender: TObject);

var

 i, j              : Integer;

begin

 //determine if we can move or condense any further downwards

 for i := Pred(GridView6.RowCount) downto (GridView6.RowCount - gridView6.SelectedCount) do

   if not (GridView6.Selected[i]) then

     begin

       for j := i downto 0 do

         if (GridView6.Selected[j]) then

           GridView6.MoveRow(j, j + 1);

       Break;

     end;

end;


Due to a 'bug' the indicator column isn't changed.

Have fun coding.
G.W. van der Vegt




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users