[C++Builder 2007] TTreeView & CheckBox
Как в C++Builder 2007 сделать элементы в TTreeView с CheckBox"ами ?
|
Сам отвечу на свой вопрос:)
Код:
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
DWORD dwStyle = GetWindowLong(TreeView1->Handle, GWL_STYLE);
dwStyle = dwStyle | TVS_CHECKBOXES;
SetWindowLong(TreeView1->Handle, GWL_STYLE, dwStyle);
}
//Програмно устанавливаем значения флажков----------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TreeView1->Items->Item[0]->StateIndex=2;
TreeView1->Items->Item[0]->Item[0]->StateIndex=1;
}
//Програмно читаем значения флажков---------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Label1->Caption =TreeView1->Items->Item[0]->StateIndex ;
}
//Следим за изменениями флажков и ставим StateIndex
void __fastcall TForm1::TreeView1MouseDown(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
{
THitTests MH = TreeView1->GetHitTestInfoAt(X,Y);
if(MH.Contains(htOnStateIcon))
{
TTreeNode *Node = TreeView1->GetNodeAt(X,Y);
if(Node->StateIndex == 1)
{
Node->StateIndex = 2;
}
else
{
Node->StateIndex = 1;
}
}
}
}
|
Время: 07:48.
© OSzone.net 2001-