Topic: Problem selecting a single cell in a tablegrid

I have a TableGrid it has  5 columns.  Column 5 has a checkbox enabled by selecting checkbox under 'settings'.

My intention is to click in cell 5 on a specific row and cause the current date to be entered into cell 4. I then want to change the font color of the row.

I have the code below  which partly works, the checkbox appears and the date does get entered into the correct cell.

However, I can click anywhere on the row to get this to happen, what I want is to have just column 5 cell to perform the date function when clicked.

I can't get the row font colour to change at all, though I would be just as happy to have a row grayed out.

procedure frmMain_grdOrders_OnCellClick (Sender: TObject; ACol, ARow: Integer);
 var
     YY,MM,DD:Word;

begin
    DecodeDate(frmMain.DateTimePicker1.DateTime,YY,MM,DD); //get only the date portion of datetime

    if frmMain.grdOrders.Cell[5,ARow].Empty = false then    //checkbox is unticked
    begin
        frmMain.grdOrders.Cell[4,ARow].AsDateTime := EncodeDate(YY,MM,DD); 
        frmMain.grdOrders.font.color:= clGreen;

    end;  
 

       
end;

Any ideas greatfully received.

Post's attachments

Attachment icon MVD_checkbox_setting.PNG 60.28 kb, 124 downloads since 2019-12-27 

On a clear disk you can seek forever

2 (edited by derek 2019-12-27 13:43:04)

Re: Problem selecting a single cell in a tablegrid

Hi CDB,
Try inserting
  if acol = 5 then............ should do the trick and limit anything to just that column.
I'm not sure why you just can't click on Column4 directly and do your date manipulation (ie if acol = 4 then........) rather than using an extra column with a checkbox - just a thought.
Attached is also something I did a couple of years ago which does a bit of 'interactive' grid work - perhaps it will give you some ideas.
Regards,
Derek.

Post's attachments

Attachment icon interactivetickbox.zip 339.45 kb, 275 downloads since 2019-12-27 

Re: Problem selecting a single cell in a tablegrid

Thanks Derek, that solved my problem.

The reason why I'm going for a checkbox to enter a date is because:

1. I want a user to definitely select a 'date received' rather than perhaps accidently clicking on the grid and entering a date, as this is a one time entry. No reversal allowed, or mistakes for that matter smile

2. I intend to have a double click on a specific cell, similar to your example and open up another form.

On a clear disk you can seek forever