Mega Search
23.2 Million


Sign Up

Make a donation  
What is the best method for on click d/click in stringgrid o  
News Group: embarcadero.public.delphi.platformspecific.ios

HI,

1. I am producing a quotation app on IOS using  a  stringgrid to select from the products and populate another stringgrid.

However using this method the click are not correctly ( a random row is selected).

procedure TTabbedForm.StringGrid2Click(Sender: TObject);
var
selectedRow,buttonSelected, newRow  : Integer;
selectedCode, selectedDesc : String;
begin
    selectedRow :=  StringGrid2.Selected;
    selectedCode := StringGrid2.Cells[0,selectedRow];
    selectedDesc := StringGrid2.Cells[1,selectedRow];
   // buttonSelected := MessageDlg('Confirmation',mtError, mbOKCancel, 0);
    buttonSelected := MessageDlg('Add '+ selectedCode +' to quote', TMsgDlgType.mtError, mbOKCancel, 0);
    //buttonSelected := 1;
  // Show the button type selected
  if buttonSelected = mrOK     then
  begin
  //ShowMessage('OK pressed');
    //showmessage('you selected ' +  selectedCode + ' desc' + selectedDesc);
    newRow := SGCustomerDetails.RowCount ;
    SGCustomerDetails.RowCount := SGCustomerDetails.RowCount + 1;
    SGCustomerDetails.cells[0,newRow] := '1';
    SGCustomerDetails.cells[1,newRow] := selectedCode;
    SGCustomerDetails.cells[2,newRow] := selectedDesc;
    SGCustomerDetails.SetFocus;

    //showmessage('you selected ' +  selectedCompany + ' image' + selectedCompanyImage);
  end;
    if buttonSelected = mrCancel then ShowMessage('Cancel pressed');
 end;

2. I also need to be able to delete a row from the populated string grid. I am using an on d/click event and running this code:

procedure TTabbedForm.SGCustomerDetailsDblClick(Sender: TObject);
var
selectedRow,buttonSelected  : Integer;
codeToDelete : string;
i, j: Integer;
begin
    selectedRow :=  SGCustomerDetails.Selected;;
    codeToDelete := SGCustomerDetails.Cells[1,selectedRow];
    //selectedCompanyImage := SGCustomerDetails.Cells[3,selectedRow];
   // buttonSelected := MessageDlg('Confirmation',mtError, mbOKCancel, 0);
    buttonSelected := MessageDlg('Delete row '+ codeToDelete , TMsgDlgType.mtError, mbOKCancel, 0);
  // Show the button type selected
  if buttonSelected = mrOK     then
  begin
  //ShowMessage('OK pressed');

    with SGCustomerDetails do
begin
    for i := selectedRow to RowCount-2 do
      for j := 0 to ColumnCount-1 do
        Cells[j, i] := Cells[j, i+1];
    RowCount := RowCount - 1
  end;


   // showmessage('you selected ' +  selectedCompany + ' image' + selectedCompanyImage);
  end;
    if buttonSelected = mrCancel then ShowMessage('Cancel pressed');
end;

This works fine under windows but not on mobile.

Is there a way I can add a button in the stringgrid row to action the delete row code ?



Thanks.

Vote for best question.
Score: 0  # Vote:  0
Date Posted: 12-Jan-2015, at 1:39 AM EST
From: Stev Warby
 
Re: What is the best method for on click d/click in stringgr  
News Group: embarcadero.public.delphi.platformspecific.ios
I  have changed to using a ListView and have been able to customise the ListView for the product list for selection.

On the on click event I can get the correct values. (ie no false triggers). I am presuming the grids are not optimised for mobiles.

I now need to build up a list with the following fields that will work on mobile.

Quantity (edit field) - PartNumber (Label) - Desc (Label) - Cost (edit field) - delete row (button).

I tried this with another ListView but it does not have enough columns for what I need.

Is there a method to do this with a listView ?

I also see a ListBox but cannot add what I need to this.

Any ideas or code would be appreciated.

Thanks.

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 12-Jan-2015, at 5:02 PM EST
From: Stev Warby