Jump to content

UniStringGrid select/deselect cell issue


fpiette

Recommended Posts

 Create a new application having a UniStringGrid and a UniButton.

Use the following code un UniButton1.click event Handler:

    UniStringGrid1.Row := -1;

    UniStringGrid1.Com := -1;

 

Clicking on UniButton1 should deselect the currently selected cell in UniStringGrid1. It doesn't work always.

 

Steps to reproduce:

1. Launch application
   -> No UniStringGrid cell selected -- Correct
2. Click on a UniStringGrid1 cell
   -> Cell selected and displayed in cyan -- Correct
3. Click UniButton1
   -> Nothing happend -- Wrong: cell should be unselected
4. Click on another UniStringGrid cell
   -> Clicked cell is selected -- Correct
   -> First selected cell remains cyan (selected) -- Wrong
5. Click on a third UniStringGrid cell
   -> Cell is selected -- Correct
   -> Previous selected cell becomes white (unselected) -- Correct
   -> First selected cell remains cyan (selected) -- Wrong
6. Click UniButton1
   -> Last selected cell becomes white (unselected) -- Correct
   -> First selected cell remains cyan (selected) -- Wrong
   

--

François Piette

Embarcadero MVP

 

Link to comment
Share on other sites

Hi,

 

 Create a new application having a UniStringGrid and a UniButton.

Use the following code un UniButton1.click event Handler:

    UniStringGrid1.Row := -1;

    UniStringGrid1.Com := -1;

 

Clicking on UniButton1 should deselect the currently selected cell in UniStringGrid1. It doesn't work always.

 

Are you sure that this should work at all ?

Link to comment
Share on other sites

UniStringGrid1.JSInterface.JSCall('getSelectionModel().deselect', []);

This works. Thanks.

 

In my opinion, UniStringGrid code should do that action in Row/Col property setter whenever the Row/Col value is invalid (Such as -1). Or provide a method to select/unselect a rectangular region in the grid.

Link to comment
Share on other sites

UniStringGrid1.JSInterface.JSCall('getSelectionModel().deselect', []);

Actually, this doesn't work 100% correctly. It deselect the cell but affect only the display. Somewhere the underlying layers doesn't know the cell is deselected. This means that clicking again on the [now supposedly unselected] cell doesn't trigger the UniStringGridSelectCell event.

Link to comment
Share on other sites

As a workaround, can you try to use this approach too ?:

 

1.

type
  TMyUniStringGrid = class(TUniBasicGrid)

  end;

2.

  with TMyUniStringGrid(UniStringGrid1) do
  begin
    JSInterface.JSCall('getSelectionModel().deselect', []); // first
    CurrCol:=-1;
    CurrRow:=-1;
  end;
Link to comment
Share on other sites

Thanks.

 

As far as I can tell right now, it works.

I have implemented a little bit differently, using a old Delphi trick to redefine an existing class (Only valid in current source file). It is enough and natural to call the new method.

type
  TUniStringGrid = class(UniStringGrid.TUniStringGrid)
  public
      procedure Deselect;
  end;
procedure TUniStringGrid.Deselect;
begin
    JSInterface.JSCall('getSelectionModel().deselect', []); 
    CurrCol := -1;
    CurrRow := -1;
end;
  • Upvote 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...