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

tstringgrid with selected text

heya delphi 6 and win2k

   i have a tstringgrid, is there a way to know the selected cell and the selected text inside a cell, i mean if inside the cell there is "hello wolrd" and the "llo wor" is blue and selected is there a way to know that selection. taking another component might not be an issue here.

thx
chad
0
Chadak
Asked:
Chadak
  • 3
  • 2
1 Solution
 
Mohammed NasmanSoftware DeveloperCommented:
Hello

  Use the Cells proeprty to return the text in specific cell, here's an example will Show you the content of selected cell, using the OnSelectCell even

procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol,
  ARow: Integer; var CanSelect: Boolean);
begin
  ShowMessage(StringGrid1.Cells[ACol,ARow]);
end;
0
 
ChadakAuthor Commented:
sorry maybe i didnt ask my question well, i knew how to get this, but how can i know what part of the text was selected with the mouse and is hightlited blue.

because i have a grid with a popupmenu, and at some moment i rightclick, pop my menu, and i need to so something with the selected value inside the cell. the cell might have 10 words in it and only 2 words might be selected and i want to get those 2 words.
0
 
mocartsCommented:
implementation
type
  // dummy class to access protected sectoin of TStringGrid
  TMyStringGrid = class(TStringGrid)
  end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  with TMyStringGrid(StringGrid1) do
    if EditorMode then
      Label1.Caption := InplaceEditor.SelText;
end;

wbr, mo.
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
mocartsCommented:
this code can be executed from TMenuItem.OnClick as well.
mo.
0
 
ChadakAuthor Commented:
Im at home this weekend will try this monday morning
0
 
ChadakAuthor Commented:
thx works well
should have think of it
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

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