• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 654
  • Last Modified:

How to save the TStringgrid selected cell coordinates to a textfile?

Hi Folks!

I want to be able to save the coordinates of the selected cell of my stringgrid so that each value covers one line. First the column then the Row. This file should look somehting like this:

4
3
5
3
6
3
7
3

It would be perfect when I had some way of constantly tracking those coordinates whilst being able to save both values of the selected cell by means of a button click. Five clicks would then result in 5 x 2 values > some 10 lines textfile.
If you need more info dont hesitade to ask.


regards,

Peter

(reference > one of my other questions regarding TStringgrid answered by Mokule)
0
PeterdeB
Asked:
PeterdeB
  • 3
  • 2
1 Solution
 
PeterdeBAuthor Commented:
I just managed to get the values btw. So I'm on my way to the solution :)

Peter
0
 
PeterdeBAuthor Commented:
Done!!  here's what I did >


// SGEDIT being a stringgrid
// LBVALUES a listbox
// EDITCOL and EDITROW spinedits
// All thingies starting with BTN being buttons

procedure TForm1.SGEDITSelectCell(Sender: TObject; ACol, ARow: Integer;
  var CanSelect: Boolean);
begin
EDITCOL.Value := ACol+1;
EDITROW.Value := ARow+1;
end;

procedure TForm1.BTNADD2LBClick(Sender: TObject);
begin
LBVALUES.Items.Add(EDITCOL.Text);
LBVALUES.Items.Add(EDITROW.TExt);
end;

procedure TForm1.BTNREMITEMClick(Sender: TObject);
begin
LBVALUES.Items.Delete(LBVALUES.ItemIndex);
end;

procedure TForm1.BTNCLEARLBClick(Sender: TObject);
begin
LBVALUES.Clear;
end;

procedure TForm1.btnSaveItemsLBClick(Sender: TObject);
begin if
spSkinSavedialog1.Execute then
LBVALUES.Items.SaveToFile(spSkinSaveDialog1.FileName);
end;

// feel free to improve this approach cause Im sure you can and if you do you may be entitled to the points anyway :)

Regards,

Peter
0
 
more2chanceCommented:
if what you want is the row/column reference of the selected cell, use

grid.Row
grid.Col

where grid is your TStringsGrid object. These two properties will point to the currently selected cell. To extract contents of a cell

myString := grid.Cell[grid.Col, grid.Row];
0
 
PeterdeBAuthor Commented:
Hi More2Chance!

I just took your code since I wanted to get my hands on the cell contents. So the points are yours!

Regards,

Peter :)
0
 
more2chanceCommented:
anytime.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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