?
Solved

Double-clicking a frozen column/row

Posted on 2003-03-10
5
Medium Priority
?
404 Views
Last Modified: 2010-04-04
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
Comment
Question by:ctjoumas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 9

Accepted Solution

by:
mocarts earned 225 total points
ID: 8103655
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
 

Author Comment

by:ctjoumas
ID: 8104390
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
 

Author Comment

by:ctjoumas
ID: 8104429
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
 
LVL 9

Expert Comment

by:mocarts
ID: 8106417
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
 

Author Comment

by:ctjoumas
ID: 8112004
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month9 days, 22 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question