請問各位先進
小弟想在dbgrid的第一個欄位中加入dbcheckbox
以供選取 被選取的資料(右邊的欄位內容)會秀到別的Form裡面 不曉得是否要在資料庫新增一個"選擇"的欄位(資料型態為布林)
還是用dbgrid來新增一個虛擬的"選擇"欄位 那個比較適合呢?? 爬過許多文章 大都提到使用delphi來做 (看不懂)...
怎麼用bcb的語法達成?? 下圖是我新增一個虛擬欄位(欄位名稱"選擇")
目的是在選擇裡放入dbcheckbox.....
[Note]
我參考http://delphi.ktop.com.tw/topic.php?TOPIC_ID=48816
的delphi程式, 修改成bcb有出現一些問題 程式碼如下:
//--------------------------------------------------------------------------- #include
#pragma hdrstop #include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//--------------------------------------------------------------------------- void __fastcall TForm1::DBGrid1DrawDataCell(TObject *Sender,
const TRect &Rect, TField *Field, TGridDrawState State)
{
if (State.Contains(gdFocused))
{
if (Field->FieldName == DBCheckBox1->DataField)
{
DBCheckBox1->Left = Rect.Left + DBGrid1->Left + 1;
DBCheckBox1->Top = Rect.Top + DBGrid1->Top + 1;
DBCheckBox1->Width = Rect.Right - Rect.Left;
DBCheckBox1->Height = Rect.Bottom - Rect.Top;
DBCheckBox1->Visible = True;
}
}
else
{
if ( Field->FieldName == DBCheckBox1->DataField )
{
if (TableGridDataCheckBox->AsBoolean)//出現未定義TableGridDataCheckBox
DBGrid1->Canvas->Draw(Rect.Left,Rect.Top, ImageTrue->Picture->Bitmap);
else
DBGrid1->Canvas->Draw(Rect.Left,Rect.Top, ImageFalse->Picture->Bitmap);
}
}
}
//--------------------------------------------------------------------------- void __fastcall TForm1::DBGrid1ColExit(TObject *Sender)
{
if (DBGrid1->SelectedField->FieldName == DBCheckBox1->DataField) //Illegal structure operation
DBCheckBox1->Visible = false; }
//---------------------------------------------------------------------------
void __fastcall TForm1::DBCheckBox1Click(TObject *Sender)
{
if (SendMessage(DBCheckBox1->Handle, BM_GetCheck, 0, 0) == 0)//Undefined symbol 'BM_GetCheck'
DBCheckBox1->Caption = " " + "False"; //Invalid pointer addition
else
DBCheckBox1->Caption = " " + "True"; //Invalid pointer addition
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
//Database1->Params->Add("Path="+ExtractFileDir(Application.EXEName));
//Database1->Open;
//TableGridData->Open;
//DBLookupCombo1->Visible = False;
DBCheckBox1->Visible = False;
//DBComboBox1->Visible = False;
ImageTrue->Visible = False;
ImageFalse->Visible = False;
}
//---------------------------------------------------------------------------
上面有紅色的地方是出錯的地方 請各位先進看看怎麼修改呢??
謝謝 發表人 - odyaho 於 2005/07/22 00:44:49