?
Solved

Stringgrid visible selection not the same as actual row selected

Posted on 2006-06-04
5
Medium Priority
?
525 Views
Last Modified: 2010-04-05
Ok hopefully Im missing something obvious but I cant seem to spot it.

Im populating a stringgrid with a number of records (set to rowselect)
The user can then double click a row and open up another form to view more information.

When the user closes the second form it clears the previous records in the stringgrid and repopulates it so that the selected record is now moved to the top of the list.
Im calling the OnSelectCell event of the stringgird to auto select the top row (ie the record they just viewed).
My problem is the actual visual row selected still shows at the last position double clicked.

ie if the user double clicks row 5 and opens up the second form then closed, I call SelectCell of the first row various settings change to show that the first row is selected, but the visible area shown still shows row 5.

Am I missing something?
0
Comment
Question by:mikelittlewood
  • 3
  • 2
5 Comments
 
LVL 15

Author Comment

by:mikelittlewood
ID: 16827677
Do I have to call the Stringgrid.Selection function to show the visibility?

Or do I have to call the OnClick function first?
0
 
LVL 28

Expert Comment

by:2266180
ID: 16831247
hey mike,

here's my test code:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids;

type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    procedure FormCreate(Sender: TObject);
    procedure StringGrid1DblClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var i,j:integer;
begin
  for j:=1 to StringGrid1.ColCount do
    stringgrid1.Cols[j].Clear;
  stringgrid1.RowCount:=51;
  for i:=1 to 50 do
    for j:=1 to StringGrid1.ColCount do
      stringgrid1.Cols[j-1].Add(inttostr(j)+inttostr(i))
end;

procedure TForm1.StringGrid1DblClick(Sender: TObject);
begin
  StringGrid1.TopRow:=StringGrid1.Row;// this?
end;

end.

works fine. I am not sure if I udnerstood your request though. Is that what you were looking for?
0
 
LVL 15

Author Comment

by:mikelittlewood
ID: 16831630
Not quite Ciuly, but I think I have found a work around.

Imagine 10 rows in a stringgrid.
I double click row 5 (it row selects and then opens up another form based on some details in that row)
I then close the second form and repopulate the 10 rows again as changes may have occured with records.
When I repopulate the grid it reorders them fine so that the previously double clicked record is now at the top.

Problem is that visually it still shows row 5 as being currently selected, even though I have told the application to select row 1.
The application has actually selected row 1 because other events on the form have modified certain menu properties, its just the visual element.
Its a bit strange I know, but I used a work around of setting Stringgrid1.Selection := TGridRect of top row.
0
 
LVL 28

Accepted Solution

by:
2266180 earned 500 total points
ID: 16831662
well .. I guess it must have been something to do with the way you made the selection of top row.
however, I think that the reverse:
  StringGrid1.Row:=StringGrid1.TopRow;
should also make the problem go away. (having in mind that the rows must not move (since they are already sorted and in the right place) and only the selection needs to change.
I hope this time I got it right :)
in any case, it's good that it's fixed.
0
 
LVL 15

Author Comment

by:mikelittlewood
ID: 16841465
yeah your way worked as well Ciuly so Ill give you the points.
might alter the code later once I work out which is the best method.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

862 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