Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 10 of 11 total
Thread Get list of selected Grid rows
Wed, Oct 19 2016 3:13 PMPermanent Link

thomh

Hi,

I have an unbound grid with MultiSelect = True.
I select 4 out of 10 rows in the grid.
How can I read the values from these 4 rows?

Thanks.

// Thom
Wed, Oct 19 2016 3:41 PMPermanent Link

Raul

Team Elevate Team Elevate

On 10/19/2016 3:13 PM, thomh wrote:
> I have an unbound grid with MultiSelect = True.
> I select 4 out of 10 rows in the grid.
> How can I read the values from these 4 rows?

You have to check if they are selected - see EWB manual for MultiSelect
"The SelectedCount property can be examined to find out how many rows
are selected and the Selected property can be examined to find out which
rows are selected."

Basically loop thru rows : simple sample below shows value from 1st column:

for i := 0 to MyGrid.rowcount-1 do
  begin
   if MyGrid.Selected[i] then
   begin
     showMessage('Row '+inttostr(i) + ' selected.  Col1 Value = ' +
MyGrid.Rows[i][0]);
   end;
  end;

Raul
Wed, Oct 19 2016 4:05 PMPermanent Link

thomh

Thanks, Raul.

And if I wanted to delete these 4 selected rows from the grid?

// Thom
Wed, Oct 19 2016 4:11 PMPermanent Link

Trinione

thomh:
<< And if I wanted to delete these 4 selected rows from the grid? >>

Same approach.

for i := 0 to MyGrid.rowcount-1 do
 begin
  if MyGrid.Selected[i] then MyGrid.DeleteRow;
 end;
Wed, Oct 19 2016 4:31 PMPermanent Link

thomh

Hi,Trinione.

I got 5 rows in the grid.

With your code:

If I select row 2 and 3, only row 3 is deleted.

If I select row 4 and 5, only row 5 is deleted.

If I select all 5 rows, row 5 is deleted and I get an error:
"List index 4 out of bounds".

// Thom
Wed, Oct 19 2016 4:41 PMPermanent Link

Walter Matte

Tactical Business Corporation

DOWNTO

for i := MyGrid.rowcount-1 downto 0
begin
 if MyGrid.Selected[i] then MyGrid.DeleteRow;
end;

Walter
Thu, Oct 20 2016 1:43 AMPermanent Link

thomh

Hi Walter,

I got 5 rows in the grid.

Using DOWNTO:

If I select row 1, 2 and 3, row 3, 4, 5 is deleted.

If I select row 2 and 3, row 4 and 5 is deleted.

If I select row 4 and 5, row 5 is deleted and I get error:
"List index 4 out of bounds".

// Thom
Thu, Oct 20 2016 2:18 AMPermanent Link

thomh

Using SetToRow to update the RowIndex before DeleteRow seems to work.

// Thom
Thu, Oct 20 2016 4:11 AMPermanent Link

Walter Matte

Tactical Business Corporation

Good information - thanks for letting us know.

Walter



thomh wrote:

Using SetToRow to update the RowIndex before DeleteRow seems to work.

// Thom
Thu, Oct 20 2016 4:58 AMPermanent Link

thomh

Further testing revealed some wonky results using SetToRow depending on which records I select.

Seems you need set the SetToRow ShiftKey and CtrlKey parameters appropriately.

For me it works well when I use SetToRow(i, False, True).

// Thom
Page 1 of 2Next Page »
Jump to Page:  1 2
Image