0

I'm using Delphi XE8 for developing mobile application and I'm facing some of the problem in TStringGrid.

  1. I have written the following code in StringGridSelectCell event.

Showmessage(StringGrid.Cells[0, ARow]);

And this shows the proper value of the selected row at the first time. But when I have tried to click again the selected row, this event is not getting fired. And I cant able to unselect the particular row.

  1. So, I have tried to write this message in OnClick event.

    var iRowInd: Integer; begin iRowInd := StringGrid1.Selected; ShowMessage(StringGrid.Cells[0, iRowInd]); end;

And this is not working at the first time of the click and when I clicked for the second time it works properly. This issue is only in android mobile and not in Windows.

  1. Later, I have kept both the event code and then also I faced another issue. When I'm scrolling the Grid, it is firing the onClick event. So, it is displaying the previously selected Row value.

Please provide me some solution. And Thanks in Advance.

2 Answers2

1

Let's do this with OnClick event:

procedure TfmMain.StringGrid1Click(Sender: TObject);
begin
  Caption := 'Selected ROW ID: ' + StringGrid1.Selected.ToString + '. Selected COLUMN ID: ' + StringGrid1.ColumnIndex.ToString + '. Action at: ' + DateTimeToStr(Now);
end;

property TStringGrid.Selected will return ROW ID (Starting from Zero)

and

property TStringGrid.ColumnIndex will return COLUMN ID (Starting from Zero)

Zam
  • 2,880
  • 1
  • 18
  • 33
  • 1
    I have used this but still I'm facing the issue. As I have explained earlier, at the first time is not providing the proper selected item and when I'm scrolling the Grid Items it is always firing the onClick event. This problem is only in Android mobile and in desktop Windows it's fine. Please provide me the solution and TGrid also giving the same problem, – Work 2 Enjoy - Enjoy 2 Work Jun 30 '15 at 17:31
  • "at the first time is not providing the proper selected item" -- yes, i see now. "when I'm scrolling the Grid Items it is always firing the onClick event" -- yes, it's true. may be you could verify in OnClick event, if ColumnID and RowID the same as before, then just leave from OnClick procedure? – Zam Jun 30 '15 at 18:58
  • Is there any option to deselect the selected row. So, that I can proceed further easily. In VCL I fount some of examples for [Deselecting the selected Row](http://www.delphigroups.info/2/74/311196.html). **And is there any possible things can be handle in Draw cell event for Deselecting the selected Row**? – Work 2 Enjoy - Enjoy 2 Work Jul 01 '15 at 05:55
0

As of now, I have used the Material Design in the Form. And first the user needs to Select the Grid. Then, the user needs to click the button and after that I'm proceeding my logic. This makes the good application GUI and makes the functionality also proper.