<!--CodeS-->
function FindTextForStringGrid(StringGrid: TStringGrid; const Text: string): Integer;
function FindText(StringGrid: TStringGrid; const Text: string): Integer;
// Result: if found Text returns RowIndex, else returns -1
var
ColIndex, RowIndex: Integer;
begin
Result := -1;
for RowIndex := 0 to StringGrid.RowCount - 1 do
begin
for ColIndex := 0 to StringGrid.ColCount - 1 do
begin
if Pos(StringGrid.Cells[ColIndex, RowIndex], Text) <> 0 then // Found
begin
Result := RowIndex;
Exit;
end;
end;
end;
end;
var
RowIndex: Integer;
TopRowIndex: Integer;
SelRect: TGridRect;
begin
RowIndex := FindText(StringGrid, Text);
if RowIndex <> -1 then
begin
TopRowIndex := RowIndex - StringGrid.VisibleRowCount + StringGrid.FixedRows;
if TopRowIndex < StringGrid.FixedRows then
TopRowIndex := StringGrid.FixedRows;
StringGrid.TopRow := TopRowIndex;
SelRect.Left := 0;
SelRect.Top := RowIndex;
SelRect.Right := StringGrid.ColCount;
SelRect.Bottom := RowIndex;
StringGrid.Selection := SelRect;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
FindTextForStringGrid(StringGrid1, '홍길동');
end;
TAdvStringGrid를 사용합니다. AdvStringGrid의 임의의 셀에서 문자를 찾아 그 위치로 이동하려고 합니다. 물론 화면에서 찾은 Row를 보여줘야 하고요 어떻게 해야 되나요? 예를들어 AdvStringGrid1.Cells[21,0]에 '홍길동'이란 이름이 있...
최용일
•
2005.03.17 22:40
안녕하세요. 최용일입니다.
아래와 같이 해보세요...
<!--CodeS-->
function FindTextForStri...
아래와 같이 해보세요...
<!--CodeS-->
function FindTextForStringGrid(StringGrid: TStringGrid; const Text: string): Integer;
function FindText(StringGrid: TStringGrid; const Text: string): Integer;
// Result: if found Text returns RowIndex, else returns -1
var
ColIndex, RowIndex: Integer;
begin
Result := -1;
for RowIndex := 0 to StringGrid.RowCount - 1 do
begin
for ColIndex := 0 to StringGrid.ColCount - 1 do
begin
if Pos(StringGrid.Cells[ColIndex, RowIndex], Text) <> 0 then // Found
begin
Result := RowIndex;
Exit;
end;
end;
end;
end;
var
RowIndex: Integer;
TopRowIndex: Integer;
SelRect: TGridRect;
begin
RowIndex := FindText(StringGrid, Text);
if RowIndex <> -1 then
begin
TopRowIndex := RowIndex - StringGrid.VisibleRowCount + StringGrid.FixedRows;
if TopRowIndex < StringGrid.FixedRows then
TopRowIndex := StringGrid.FixedRows;
StringGrid.TopRow := TopRowIndex;
SelRect.Left := 0;
SelRect.Top := RowIndex;
SelRect.Right := StringGrid.ColCount;
SelRect.Bottom := RowIndex;
StringGrid.Selection := SelRect;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
FindTextForStringGrid(StringGrid1, '홍길동');
end;
<!--CodeE-->
항상 즐코하세요...