C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 팁&트릭
C++Builder Programming Tip&Tricks
[734] [Controls] TStringGrid InsertRow , DeleteRow , InsertCol ,DeleteCol
장성호 [nasilso] 17370 읽음    2008-01-14 16:02
TStringGrid에는
Row나 Column을 insert하거나 Delete하는 method를 제공하지 않는다..

대개 insert 를 하는경우 RowCount를 하나 증가하고
insert 한  row 부터 끝까지 하나씩 뒤로 뒤로 옮기는 것으로 하는것 같다.

뭐 같은 원리지만..
TCustomGrid 의 procted 함수에 보면 MoveRow , MoveColumn이라는 함수를 제공한다.
이 함수는 특정index의 row를 원하는 곳으로 이동시키고 ...
그사이에 row들을 하나씩 전체 밀어준다.


이미 만들어져있는 TCustomGrid 의  MoveRow , MoveColumn 함수를 이용하여
InsertRow , DeleteRow , InsertColumn , DeleteColumn을 만들어서 사용하면 더욱깔끔할것 같다.

class TMyGrid : public TStringGrid
{
public:
    void __fastcall InsertRow( int idx)
    {
        this->RowCount=this->RowCount+1;
        this->MoveRow(this->RowCount-1,idx);
    }
    void __fastcall DeleteRow(int idx)
    {
         this->MoveRow(idx,this->RowCount-1);
        this->RowCount=this->RowCount-1;
    }
    void __fastcall ChangeRow(int idx1,int idx2)
    {
        TStringList *lst=new TStringList;
        lst->Assign(this->Rows[idx1]);
        this->Rows[idx1]=this->Rows[idx2];
        this->Rows[idx2]=lst;
        delete lst;
    }
    void __fastcall InsertCol(int idx)
    {
        this->ColCount=this->ColCount+1;
        this->MoveColumn(this->ColCount-1,idx);
    }
    void __fastcall DeleteCol(int idx)
    {
        this->MoveColumn(idx,this->ColCount-1);
        this->ColCount=this->ColCount-1;
    }

};
//---------------------------------------------------------------------------


사용
    //Row Insert
    ((TMyGrid*)StringGrid1)->InsertRow(2);
    //Row Delete
    ((TMyGrid*)StringGrid1)->DeleteRow(3);
    //Column Insert
    ((TMyGrid*)StringGrid1)->InsertCol(4);
    //Column Delete
    ((TMyGrid*)StringGrid1)->DeleteCol(5);
    ..


참조
http://www.delphi.co.kr/zboard/view.php?id=tips&page=78&sn1=&divpage=1&sn=off&ss=on&sc=on&select_arrange=headnum&desc=asc&no=207


추신 2010-03-30

//일부 델파이 버젼을 추가합니다.
type

  TMyGrid = class(TStringGrid)
  public
    procedure InsertRow(idx: Integer);
    procedure DeleteRow(idx: Integer);
    procedure ChangeRow(idx1,idx2:Integer);

  end;


var
  Form1: TForm1;

implementation

{ TMyGrid }

procedure TMyGrid.InsertRow(idx: Integer);
begin
  self.RowCount:=self.RowCount+1;
  self.MoveRow(self.RowCount-1,idx);
end;

procedure TMyGrid.DeleteRow(idx: Integer);
begin
  self.MoveRow(idx,self.RowCount-1);
  self.RowCount:=self.RowCount-1;
end;

procedure TMyGrid.ChangeRow(idx1, idx2: Integer);
var
  lst:TStringList;
begin
  lst:=TStringList.Create;
  lst.Assign(self.Rows[idx1]);
  self.Rows[idx1]:=self.Rows[idx2];
  self.Rows[idx2]:=lst;
  lst.free;
end;


그럼..
아루스 [tinydew4]   2008-05-23 14:08 X
DeleteRow, DeleteCol 은 이미 있는 메소드네요.
DeleteRow, DeleteColumn 으로 구현되있습니다.
장성호 [nasilso]   2009-08-24 23:40 X
그렇군요...

+ -

관련 글 리스트
734 [Controls] TStringGrid InsertRow , DeleteRow , InsertCol ,DeleteCol 장성호 17370 2008/01/14
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.