|
폼에 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..
참고로..
헬프 찾아봤는데..
제가 못찾는건지 전 안보이더라구요..ㅜㅜ;
|