|
DB프로그램을 만들고 있는데 이해가 안되는 부분이 있어서 이렇게 물어 봅니다..
DBGrid 위에 DBCheckBox 와 ADOQuery를 하나 놓고 실행 시키는 프로그램 으로
DBGrid에 DBCheck box를 넣는것 입니다..델파이의 소스를 찾아서 일부를 수정했는데... 이상하게 DBCheckBox에 클릭을 하면 색깔이 바로 변하지 않고 두번 클릭해야 변화가 되고 업데이트가 가능하던데 이런 문제는 어떤식으로 처리 해야 되나요!!!!(마우스 오른쪽 버튼을 클릭하고 다시 윈쪽 버튼을 클릭해야 수정이 가능하게 DBnavigator 버튼이 변하게 됩니다.)
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
ADOQuery1->Close();
ADOQuery1->SQL->Clear();
ADOQuery1->SQL->Add("SELECT * FROM Articles");
ADOQuery1->Open();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
DBCheckBox1->DataSource = DataSource1;
DBCheckBox1->DataField = "Winner";
DBCheckBox1->Visible = False;
DBCheckBox1->Color = DBGrid1->Color;
DBCheckBox1->Caption = "";
//explained later in the article
DBCheckBox1->ValueChecked = "출고";
DBCheckBox1->ValueUnchecked = "미출고";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::DBGrid1DrawColumnCell(TObject *Sender,
const TRect &Rect, int DataCol, TColumn *Column,
TGridDrawState State)
{
const bool ISChecked[]=
{int(DFCS_BUTTONCHECK), int(DFCS_BUTTONCHECK)||int(DFCS_CHECKED)};
int DrawState;
TRect DrawRect;
if(State.Contains(Grids::gdFocused))
{
if (Column->Field->FieldName == DBCheckBox1->DataField) {
DBCheckBox1->Left = Rect.Left + DBGrid1->Left + 27;
DBCheckBox1->Top = Rect.Top + DBGrid1->Top+2;
DBCheckBox1->Width = Rect.Right - Rect.Left;
DBCheckBox1->Height = Rect.Bottom - Rect.Top;
DBCheckBox1->Visible = true; }
}
else
{
if (Column->Field->FieldName == DBCheckBox1->DataField) {
DrawRect=Rect;
InflateRect( (RECT *)(&DrawRect),-1,-1);
DrawState = ISChecked[Column->Field->AsBoolean];
DBGrid1->Canvas->FillRect(Rect);
DrawFrameControl(DBGrid1->Canvas->Handle, (RECT *)(&DrawRect),
DFC_BUTTON, DrawState); }
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::DBGrid1ColExit(TObject *Sender)
{
if (DBGrid1->SelectedField->FieldName == DBCheckBox1->DataField)
DBCheckBox1->Visible = false;
}
|