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

C++빌더 Q&A
C++Builder Programming Q&A
[26841] 나 죽네..--; (특정셀의 배경색 바꾸기..)
요구르트 [] 1260 읽음    2003-08-21 13:56
폼에 StringGrid나 DBGrid를 이용해서 데이타를 출력하고요..
그중 특정 필드의 값에 따라 그 셀의 색깔을 바꾸려고 하거든요.

일단 StringGrid를 해보고 있는데요..

답변에서 StringGrid1DrawCell를 이용하라고 하셔서..

간단하게..
버튼을 누르면 지정한 셀의 색깔이 바뀌도록 해봤더니 되더라구요..

void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int ACol,
      int ARow, TRect &Rect, TGridDrawState State)
{

if(ACol == stcol && ARow == strow)
{
  long index = ARow * StringGrid1->ColCount + ACol;
  StringGrid1->Canvas->Brush->Color = ColorBox1->Selected;
  StringGrid1->Canvas->FillRect(Rect);
  ImageList1->Draw(StringGrid1->Canvas,Rect.Left,Rect.Top,index);
  if (State.Contains(gdFocused))
    StringGrid1->Canvas->DrawFocusRect(Rect);
  }
}

이렇게 해놓고,,

버튼을 누르면,

전역변수인 stcol, strow를 바꾸게 하거든요..

버튼 {
ColorBox1->ItemIndex = 10;
stcol = 3, strow=9;

// 이렇게 하고 StringGrid를 다시 뿌리거든요..

}


이렇게 하면 하나의 셀은 바뀌는데..


문제는 StringGrid를 출력할때..
DB에서 데이타를 읽어와서 다수의 셀의 색깔을 바꾸는게 안되네요..

간단하게 제가 만든거거든요..


if(Query1->Active) Query1->Close();

Query1->SQL->Clear();
Query1->SQL->Add("select * from new.DB");
Query1->ExecSQL();
Query1->Open();

TLocateOptions Options;
Options = Options << loCaseInsensitive;

for(i=1; i<=5; i++)
{
  if(Query1->Locate("ID","00"+IntToStr(i),Options))
  {
   if(StrToInt(Query1->FieldByName("ID")->AsString) != 47) // 47이 기본입니다.
   {
     stcol = 4, strow = i; //바꿔야할 셀 지정..
     ColorBox1->ItemIndex = StrToInt(Query1->FieldByName("ID")->AsString); // 바꿔야할 셀의 색깔지정.
   }

   StringGrid1->Cells[1][i] = Query1->FieldByName("ID")->AsString;
   StringGrid1->Cells[2][i] = Query1->FieldByName("NAME")->AsString;
   StringGrid1->Cells[3][i] = Query1->FieldByName("TEL")->AsString;
  }
}

이렇게 만들어 봤는데 안되네요..

아무래도 StringGrid1DrawCell이벤트에 대해 잘못 이해하고 있는것 같은데..

아아..
좀 도와주세요..--;


그리고 StringGrid가 아니라 DBGrid에서 위의 경우처럼..
데이타를 읽어오면서 그 데이타의 값을 비교해서 셀의 색깔을 바꿔줄수 있나요..??

간단한 예문좀..
부탁드려요..--;

되도록이면 DBGrid..

참고로..
헬프 찾아봤는데..
제가 못찾는건지 전 안보이더라구요..ㅜㅜ;

+ -

관련 글 리스트
26841 나 죽네..--; (특정셀의 배경색 바꾸기..) 요구르트 1260 2003/08/21
26858     Re:나 죽네..--; (특정셀의 배경색 바꾸기..) smleelms 2545 2003/08/21
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.