Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 405
  • Last Modified:

Double-clicking a frozen column/row

I am using a TStringGrid and want to be able to select a record when the user double clicks a gray frozen column/row.  TStringGrid cannot, I suppose, receive focus on a frozen cell - so the unwanted behavior that occurs is that when a frozen cell is double-clicked, the currently highlighted record is displayed.  Is there any way that I can select the record that is double-clicked when double-clicking a frozen cell?

Thanks,

Chris
0
ctjoumas
Asked:
ctjoumas
  • 3
  • 2
1 Solution
 
mocartsCommented:
procedure TForm1.StringGrid1DblClick(Sender: TObject);
var
  C, R: integer;
  gr: TGridRect;
begin
  with StringGrid1.ScreenToClient(Mouse.CursorPos) do
    StringGrid1.MouseToCell(X, Y, C, R);
  with StringGrid1 do begin
    if (C < FixedCols) and (R < FixedRows) then
    begin
      // select all
      gr.Left := FixedCols;
      gr.Top := FixedRows;
      gr.Bottom := RowCount;
      gr.Right := ColCount;
      Selection := gr;
    end else
      if C < FixedCols then begin
        // Select row
        gr.Left := FixedCols;
        gr.Right := ColCount;
        gr.Top :=  R;
        gr.Bottom := R;
        Selection := gr;
      end else
        if R < FixedRows then begin
          // Select col
          gr.Left := C;
          gr.Right := C;
          gr.Top :=  FixedRows;
          gr.Bottom := RowCount;
          Selection := gr;
        end;
  end;
end;

wbr, mo.
0
 
ctjoumasAuthor Commented:
Thanks for the reply.  Ok, here is what I have (I only want to select *one* row):

With sgdGrants.ScreenToClient(Mouse.CursorPos) Do
Begin
  sgdGrants.MouseToCell(X, Y, C, R);

  // we want to select this row (R)
  If (C < sgdGrants.FixedCols) Then
  Begin
    gr.Left := sgdGrants.FixedCols;
    gr.Right := sgdGrants.ColCount;
    gr.Top := R;
    gr.Bottom := R;
    sgdGrants.Selection := gr;
  End;
End;

This works fine, but there is one problem (that I'm still looking in to) - after I select a row using the above code and then try to scroll down using the mouse wheel, I get an "EInvalidGridOperation with message 'Grid index out of range'".

Am I doing anything strange here?

Thanks,

Chris
0
 
ctjoumasAuthor Commented:
Thanks for the reply.  Ok, here is what I have (I only want to select *one* row):

With sgdGrants.ScreenToClient(Mouse.CursorPos) Do
Begin
  sgdGrants.MouseToCell(X, Y, C, R);

  // we want to select this row (R)
  If (C < sgdGrants.FixedCols) Then
  Begin
    gr.Left := sgdGrants.FixedCols;
    gr.Right := sgdGrants.ColCount;
    gr.Top := R;
    gr.Bottom := R;
    sgdGrants.Selection := gr;
  End;
End;

This works fine, but there is one problem (that I'm still looking in to) - after I select a row using the above code and then try to scroll down using the mouse wheel, I get an "EInvalidGridOperation with message 'Grid index out of range'".

Am I doing anything strange here?

Thanks,

Chris
0
 
mocartsCommented:
I provided code referencing Q title i.e. clicking on column/row :)
what you exactly want to do? maybe you can use simpe goRowSelect Option of grid? and set row when double clicked on FixedCol?
or you want to edit content of grid and this row select is needed only as such behaviour of grid?
mo.
0
 
ctjoumasAuthor Commented:
The code you posted was fine - I just needed the small part of it though (what I have posted) to do what I want.  All I want to happen is when someone clicks or double clicks on a frozen cell, the corresponding row should be highlighted.  This is working now...thanks :)

Chris
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now