Q&A
HOME
Tips & Tech
Q&A
Discuss
Download
자유게시판
홍보 / 광고
구인 / 구직
LOGIN
회원가입
stringgrid에서 정렬하는예좀 알려주십시요..제발
델파이 시작한지 얼마안되는 초보자입니다..
비주얼 베이직만 하다가 델파이를 시작했는데
스트링 그리드 소트하는 법이 나와있는 책들을
찾을수가 없어서요..
제발 스트링그리드에서 소트하는 예좀 알려주세요..
예로 오름차순과 내림차순으로요..
제발 부탁합니다..
2
COMMENTS
씨나락
•
2001.12.03 06:58
다음과 같이 하면 될것 같네요
인터넷에서 찾은 팁입니다..
어딘지 북마크 해놓을걸
쩝....
^.^;
type
{ We will need tmpGrid to typcast our StringGrid1 to
gain access to the protected TCustomGrid function
TCustomGrid.MoveRow }
tmpGrid = class(TCustomGrid);
TForm1 = class(TForm)
StringGrid1: TStringGrid;
procedure FormCreate(Sender: TObject);
procedure StringGrid1DblClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
{...}
procedure TForm1.FormCreate(Sender: TObject);
begin
{ set our stringgrid to allow editing }
StringGrid1.Options := StringGrid1.Options + [goEditing];
{ set stringgrid1 to a better height then it's
normal default }
StringGrid1.DefaultRowHeight := 20;
{ remove fixed cols }
StringGrid1.FixedCols := 0;
{ set column count }
StringGrid1.ColCount := 3;
{ set column headers }
StringGrid1.Cells[0,0] := 'First Name';
StringGrid1.Cells[1,0] := 'Last Name';
StringGrid1.Cells[2,0] := 'Department';
end;
procedure TForm1.StringGrid1DblClick(Sender: TObject);
var
x, Counter, SortColumn : integer;
tmpPoint : TPoint;
tmpCoor : TGridCoord;
begin
{ get our cursor position on the screen when we
double-click }
GetCursorPos(tmpPoint);
{ get our projects cursor position relative to the
screen position }
tmpPoint := StringGrid1.ScreenToClient(tmpPoint);
{ get our grid coord from the client cursor position }
tmpCoor := StringGrid1.MouseCoord(tmpPoint.X,tmpPoint.Y);
{ only continue if the header row was double-clicked }
if tmpCoor.y = 0 then
SortColumn := tmpCoor.X
else
Exit;
{ counter is used to get us out of the repeat }
Counter := 0;
repeat
inc(Counter);
{ start x at 1 to skip our header column }
for x := 1 to StringGrid1.RowCount - 2 do
{ compare rows }
if CompareStr(StringGrid1.Cells[SortColumn,x],
StringGrid1.Cells[SortColumn,(x+1)]) > 0 then
{ type-cast StringGrid1 with a TCustomGrid class
to gain access to the MoveRow protected function }
tmpGrid(StringGrid1).MoveRow(x+1,x);
{ change Counter=1000 if you have a super large grid }
until (Counter = 1000);
{ force StringGrid1 to repaint our changes }
StringGrid1.Repaint;
end;
{...}
Example 2
{...}
type
{ We will need tmpGrid to typcast our StringGrid1 to
gain access to the protected TCustomGrid function
TCustomGrid.MoveRow }
tmpGrid = class(TCustomGrid);
TForm1 = class(TForm)
StringGrid1: TStringGrid;
procedure FormCreate(Sender: TObject);
procedure StringGrid1DblClick(Sender: TObject);
procedure TForm1.StringGrid1MouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
private
{ Private declarations }
tmpRow,tmpCol : Integer;
public
{ Public declarations }
end;
{...}
procedure TForm1.FormCreate(Sender: TObject);
begin
{ set our stringgrid to allow editing }
StringGrid1.Options := StringGrid1.Options + [goEditing];
{ set stringgrid1 to a better height then it's
normal default }
StringGrid1.DefaultRowHeight := 20;
{ remove fixed cols }
StringGrid1.FixedCols := 0;
{ set column count }
StringGrid1.ColCount := 3;
{ set column headers }
StringGrid1.Cells[0,0] := 'First Name';
StringGrid1.Cells[1,0] := 'Last Name';
StringGrid1.Cells[2,0] := 'Department';
end;
procedure TForm1.StringGrid1MouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
begin
StringGrid1.MouseToCell(X,Y,tmpCol,tmpRow);
end;
procedure TForm1.StringGrid1DblClick(Sender: TObject);
var
x, Counter, SortColumn : integer;
begin
{ only continue if the header row was double-clicked }
if tmpRow = 0 then
SortColumn := tmpCol
else
Exit;
{ counter is used to get us out of the repeat }
Counter := 0;
repeat
inc(Counter);
{ start x at 1 to skip our header column }
for x := 1 to StringGrid1.RowCount - 2 do
{ compare rows }
if CompareStr(StringGrid1.Cells[SortColumn,x],
StringGrid1.Cells[SortColumn,(x+1)]) > 0 then
{ type-cast StringGrid1 with a TCustomGrid class
to gain access to the MoveRow protected function }
tmpGrid(StringGrid1).MoveRow(x+1,x);
{ change Counter=1000 if you have a super large grid }
until (Counter = 1000);
{ force StringGrid1 to repaint our changes }
StringGrid1.Repaint;
end;
대헌욱 wrote:
> 델파이 시작한지 얼마안되는 초보자입니다..
> 비주얼 베이직만 하다가 델파이를 시작했는데
> 스트링 그리드 소트하는 법이 나와있는 책들을
> 찾을수가 없어서요..
> 제발 스트링그리드에서 소트하는 예좀 알려주세요..
> 예로 오름차순과 내림차순으로요..
> 제발 부탁합니다..
0
0
삭제
수정
댓글
대헌욱
•
2001.12.03 21:59
정말 고맙습니다. 씨나락님^^
정말 많은 도움이 됐습니다..
이은혜 어떻게 보답해야될지..^^;
그럼 앞으로도 많은 관심 부탁드립니다..
그럼 즐거운 하루되십시요..
0
0
삭제
수정
댓글
(NOTICE) You must be
logged in
to comment on this post.
소나무
2001.12.03 21:22
0
COMMENTS
/
0
LIKES
흑흑,, 업데이트 할때 순번을 자동으로 부여하려고 하는데...
사발우성™
•
2001.12.03 21:21
1
COMMENTS
/
0
LIKES
흑흑~ ole컨테이너에서 엑셀 실행후 엑셀 죽이기 ㅠㅠ
사발우성™
•
2001.12.03 21:54
사발우성™ wrote: > 하이 고수님들.. > ole컨테이너에서 엑셀을 불러들였는데엽... close시 excel proces...
궁금이
2001.12.03 21:20
0
COMMENTS
/
0
LIKES
Windows XP에서 delphi 5.0 의 TEdit 박스에 한글이 입력않되는점
초보초보
2001.12.03 21:18
0
COMMENTS
/
0
LIKES
급합니다. 컴포넌트 모양이 똑같은 모양으로 바뀌었어여...ㅜ.ㅜ
초보
•
2001.12.03 20:13
1
COMMENTS
/
0
LIKES
DBGrid 내용을 지우려면....
사발우성™
•
2001.12.04 04:44
^^ 허접 사발임돠... DataSource1.DataSet := nil; 이렇게 하면 내용이 지워짐당..^^ ^^ 그럼 즐프엽 ...
하눌이
•
2001.12.03 20:05
1
COMMENTS
/
0
LIKES
Truetype글꼴등록이 ...?
하눌이
•
2001.12.04 06:34
하눌이 wrote: > 팁에서 찾아서 Truetype글꼴을 등록하는것을 적용했으나, 설치완료후에 > 제어판의 글...
prosit
•
2001.12.03 18:41
2
COMMENTS
/
0
LIKES
질문 : Listbox 정렬.
최용일
•
2001.12.03 21:00
안녕하세요. 최용일입니다. 아래와 같이 해보세요... type TMySortCompare = function (Items: TS...
prosit
•
2001.12.03 22:02
전에도 몇 번 도움을 주시더니, 오늘도 도와주시는 군요. 최 용일님께 도움을 받는 분들이 많은 것으로 ...
김장호
•
2001.12.03 14:09
1
COMMENTS
/
0
LIKES
TScreen 에 대하여
홍성락
•
2001.12.03 19:38
김장호 wrote: > > 델파이 헬프를 보니깐 TScreen에서는 스크린의 해상도와 크기를 알수 있다고 했는데 ...
이경문
2001.12.03 11:42
0
COMMENTS
/
0
LIKES
Re: 모달 폼에서 다른 폼으로 변수 전달
왕초보
•
2001.12.03 10:53
3
COMMENTS
/
0
LIKES
이미지를 버턴 처럼 쓸려는데......
이경문
•
2001.12.03 11:39
자료실 ImageButton으로 검색해 보세요. CM_MOUSEENTER, CM_MOUSELEAVE message를 사용한 겁니다. 왕초...
왕초보
•
2001.12.03 12:25
답변 감사합니다만 전 기본적인 언어지식만 있거든여 어떻게 돌아가는지 이해는 가는데여 델파이는 할줄...
이경문
•
2001.12.03 12:35
걍 컴포넌트 쓰세요. 그게 가장 쉽자나요. 왕초보 wrote: > 답변 감사합니다만 전 기본적인 언어지식만 ...
이경문
•
2001.12.03 10:26
2
COMMENTS
/
0
LIKES
C의 preprocessor(#define)기능을 어떻게 구현할까요?
최용일
•
2001.12.03 19:33
안녕하세요. 최용일입니다. 델파이에도 같은것들이 있습니다... {$ifdef ...} codes...... {$e...
이경문
•
2001.12.03 23:04
감사합니다. ^^ 최용일 wrote: > 안녕하세요. 최용일입니다. > > 델파이에도 같은것들이 있습니다.....
대헌욱
•
2001.12.03 05:47
2
COMMENTS
/
0
LIKES
stringgrid에서 정렬하는예좀 알려주십시요..제발
델파이 시작한지 얼마안되는 초보자입니다.. 비주얼 베이직만 하다가 델파이를 시작했는데 스트링 그리드 소트하는 법이 나와있는 책들을 찾을수가 없어서요.. 제발 스트링그리드에서 소트하는 예좀 알려주세요.. 예로 오름차순과 내림차...
씨나락
•
2001.12.03 06:58
다음과 같이 하면 될것 같네요 인터넷에서 찾은 팁입니다.. 어딘지 북마크 해놓을걸 쩝.... ^.^; ...
대헌욱
•
2001.12.03 21:59
정말 고맙습니다. 씨나락님^^ 정말 많은 도움이 됐습니다.. 이은혜 어떻게 보답해야될지..^^; 그럼 앞으...
김대웅
•
2001.12.03 01:51
4
COMMENTS
/
0
LIKES
쓰레드와 타이머 사용시 타이머 동작하지 않는 경우[무지급함]
srookie
•
2001.12.03 04:57
김대웅 wrote: > 안녕하세요. > > 제가 쓰레드와 타이머를 사용해서 db에 ado로 연결하는 동안 연결 시...
동급최강바보
•
2001.12.03 20:02
우선 하나씩 얘기를 할께여. 쓰레드를 생성할때(Create)에서 마지막에 Resume을 했는데 타이머 이벤트에서...
srookie
•
2001.12.04 08:16
제가 지난번에 Timer에서 Thread를 Resume한다는 것을 못보고서 답변을 드려서 허접한 답변이 나오고 말았...
김대웅
•
2001.12.05 02:40
님 알려주신데로 했는데요.. 그래도 먹통이 되네요. 서버 쪽에 컴퓨터가 꺼져 있으면요 8초정도 프로...
클마스
2001.12.02 22:00
0
COMMENTS
/
0
LIKES
퀵 리포트 : 똑같은 내용을 2copy 씩 찍으려고 하는데요....
안영진
•
2001.12.02 06:15
1
COMMENTS
/
0
LIKES
use 절에 대한 질문입니다.
치버
•
2001.12.02 08:21
자신이 쓸려고 하는 클래스를 델파이 에디터에서 씁니다. 가령 TTreeView 라고.. 그리고 그 글자에 커서...
DB2초보
2001.12.02 05:02
0
COMMENTS
/
0
LIKES
DB2 CA400 : Transaction 사용시 에러
aminay
•
2001.12.02 00:06
1
COMMENTS
/
0
LIKES
폴더를 휴지통에 버리지않고 바로 제거해 버리는 방법..
최용일
•
2001.12.03 20:09
안녕하세요. 최용일입니다. 휴지통으로 파일을 삭제하는거 보니까 SHFileOperation함수를 사용하시는 거...
남호진
2001.12.01 23:59
0
COMMENTS
/
0
LIKES
Sybase 5.0과 델파이를 BDE를 통하여 바로 연결하려면 어떤 세팅이 필요한가
보라
2001.12.01 23:30
0
COMMENTS
/
0
LIKES
ActiveX에서 퀵레포트를 사용하는데......출력이..
궁금이
2001.12.01 22:30
0
COMMENTS
/
0
LIKES
Symbol '<AllocateHWnd>' is deprecated
대헌욱
2001/12/03 05:47
Views
347
Likes
0
Comments
2
Reports
0
Tag List
수정
삭제
목록으로
한델 로그인 하기
로그인 상태 유지
아직 회원이 아니세요? 가입하세요!
암호를 잊어버리셨나요?
인터넷에서 찾은 팁입니다..
어딘지 북마크 해놓을걸
쩝....
^.^;
type
{ We will need tmpGrid to typcast our StringGrid1 to
gain access to the protected TCustomGrid function
TCustomGrid.MoveRow }
tmpGrid = class(TCustomGrid);
TForm1 = class(TForm)
StringGrid1: TStringGrid;
procedure FormCreate(Sender: TObject);
procedure StringGrid1DblClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
{...}
procedure TForm1.FormCreate(Sender: TObject);
begin
{ set our stringgrid to allow editing }
StringGrid1.Options := StringGrid1.Options + [goEditing];
{ set stringgrid1 to a better height then it's
normal default }
StringGrid1.DefaultRowHeight := 20;
{ remove fixed cols }
StringGrid1.FixedCols := 0;
{ set column count }
StringGrid1.ColCount := 3;
{ set column headers }
StringGrid1.Cells[0,0] := 'First Name';
StringGrid1.Cells[1,0] := 'Last Name';
StringGrid1.Cells[2,0] := 'Department';
end;
procedure TForm1.StringGrid1DblClick(Sender: TObject);
var
x, Counter, SortColumn : integer;
tmpPoint : TPoint;
tmpCoor : TGridCoord;
begin
{ get our cursor position on the screen when we
double-click }
GetCursorPos(tmpPoint);
{ get our projects cursor position relative to the
screen position }
tmpPoint := StringGrid1.ScreenToClient(tmpPoint);
{ get our grid coord from the client cursor position }
tmpCoor := StringGrid1.MouseCoord(tmpPoint.X,tmpPoint.Y);
{ only continue if the header row was double-clicked }
if tmpCoor.y = 0 then
SortColumn := tmpCoor.X
else
Exit;
{ counter is used to get us out of the repeat }
Counter := 0;
repeat
inc(Counter);
{ start x at 1 to skip our header column }
for x := 1 to StringGrid1.RowCount - 2 do
{ compare rows }
if CompareStr(StringGrid1.Cells[SortColumn,x],
StringGrid1.Cells[SortColumn,(x+1)]) > 0 then
{ type-cast StringGrid1 with a TCustomGrid class
to gain access to the MoveRow protected function }
tmpGrid(StringGrid1).MoveRow(x+1,x);
{ change Counter=1000 if you have a super large grid }
until (Counter = 1000);
{ force StringGrid1 to repaint our changes }
StringGrid1.Repaint;
end;
{...}
Example 2
{...}
type
{ We will need tmpGrid to typcast our StringGrid1 to
gain access to the protected TCustomGrid function
TCustomGrid.MoveRow }
tmpGrid = class(TCustomGrid);
TForm1 = class(TForm)
StringGrid1: TStringGrid;
procedure FormCreate(Sender: TObject);
procedure StringGrid1DblClick(Sender: TObject);
procedure TForm1.StringGrid1MouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
private
{ Private declarations }
tmpRow,tmpCol : Integer;
public
{ Public declarations }
end;
{...}
procedure TForm1.FormCreate(Sender: TObject);
begin
{ set our stringgrid to allow editing }
StringGrid1.Options := StringGrid1.Options + [goEditing];
{ set stringgrid1 to a better height then it's
normal default }
StringGrid1.DefaultRowHeight := 20;
{ remove fixed cols }
StringGrid1.FixedCols := 0;
{ set column count }
StringGrid1.ColCount := 3;
{ set column headers }
StringGrid1.Cells[0,0] := 'First Name';
StringGrid1.Cells[1,0] := 'Last Name';
StringGrid1.Cells[2,0] := 'Department';
end;
procedure TForm1.StringGrid1MouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
begin
StringGrid1.MouseToCell(X,Y,tmpCol,tmpRow);
end;
procedure TForm1.StringGrid1DblClick(Sender: TObject);
var
x, Counter, SortColumn : integer;
begin
{ only continue if the header row was double-clicked }
if tmpRow = 0 then
SortColumn := tmpCol
else
Exit;
{ counter is used to get us out of the repeat }
Counter := 0;
repeat
inc(Counter);
{ start x at 1 to skip our header column }
for x := 1 to StringGrid1.RowCount - 2 do
{ compare rows }
if CompareStr(StringGrid1.Cells[SortColumn,x],
StringGrid1.Cells[SortColumn,(x+1)]) > 0 then
{ type-cast StringGrid1 with a TCustomGrid class
to gain access to the MoveRow protected function }
tmpGrid(StringGrid1).MoveRow(x+1,x);
{ change Counter=1000 if you have a super large grid }
until (Counter = 1000);
{ force StringGrid1 to repaint our changes }
StringGrid1.Repaint;
end;
대헌욱 wrote:
> 델파이 시작한지 얼마안되는 초보자입니다..
> 비주얼 베이직만 하다가 델파이를 시작했는데
> 스트링 그리드 소트하는 법이 나와있는 책들을
> 찾을수가 없어서요..
> 제발 스트링그리드에서 소트하는 예좀 알려주세요..
> 예로 오름차순과 내림차순으로요..
> 제발 부탁합니다..