Articles   Members Online: 3
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to refocus a cell in a TStringGrid Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
16-Nov-02
Category
VCL-General
Language
Delphi 2.x
Views
87
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

I have a stringgrid which displays spreadsheet type figures for a year. When the 
user double clicks a cell then I take the value from one of the cells in that same 
row and bring up another DB based form so the user can work on data for that 
record. Now when they have finished editing that record, I need to repopulate the 
stringgrid, which could (and probably will) put the initial row in a different 
position. This now leaves a couple of problems: 1. I have a highlighted cell which 
doesn't correspond to anything. 2. The user doesn't know immediately which item 
they have just been working on. How can I search the string grid for the item that 
was initially selected (one of the cells in the selected row holds the primary key 
value)? When this row is found, I then need to highlight the first column of that 
row. Is the above possible? I can't seem to see any properties to achieve it.

Answer:

Maybe this helps:

1   unit Unit1;
2   
3   interface
4   
5   uses
6     Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Grids;
7   
8   type
9     TForm1 = class(TForm)
10      StringGrid1: TStringGrid;
11      procedure StringGrid1DblClick(Sender: TObject);
12      procedure StringGrid1MouseUp(Sender: TObject; Button: TMouseButton;
13        Shift: TShiftState; X, Y: Integer);
14    private
15      {Private declarations}
16    public
17      {Public declarations}
18      CurRow: integer;
19      CurCol: integer;
20    end;
21  
22  var
23    Form1: TForm1;
24  
25  implementation
26  
27  {$R *.DFM}
28  
29  procedure TForm1.StringGrid1DblClick(Sender: TObject);
30  begin
31    ShowMessage('Moving the topleft cell');
32    {Select the upper left cell}
33    with StringGrid1 do
34    begin
35      Row := 1;
36      Col := 1;
37    end;
38    {Process all pending messages}
39    Application.ProcessMessages;
40    {Wait 3 seconds}
41    Sleep(3000);
42    {Select the previously selected cell}
43    with StringGrid1 do
44    begin
45      Row := CurRow;
46      Col := CurCol;
47    end;
48    Application.ProcessMessages;
49  end;
50  
51  procedure TForm1.StringGrid1MouseUp(Sender: TObject; Button: TMouseButton;
52    Shift: TShiftState; X, Y: Integer);
53  begin
54    {Remember the selected row and column}
55    CurRow := StringGrid1.Row;
56    CurCol := StringGrid1.Col;
57  end;
58  
59  end.


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC