treeview有复选框吗?怎么用
我用的是BCB6,treeview控件有没有复选框功能?如果有,修改那个属性可以显示,如果没有怎么解决
[解决办法]
TreeView是不带CheckBox的
不过自己可以用程序实现
void __fastcall TForm1::FormCreate(TObject *Sender)
{
SetWindowLong(TreeView1-> Handle,GWL_STYLE,GetWindowLong(TreeView1-> Handle,GWL_STYLE) | TVS_CHECKBOXES);
}
//---------------------------------------
bool TForm1::GetNodeChecked(TTreeNode *ANode)
{
TVITEM tvItem;
tvItem.mask = TVIF_HANDLE | TVIF_STATE;
tvItem.hItem = ANode-> ItemId;
tvItem.stateMask = TVIS_STATEIMAGEMASK;
TreeView_GetItem(ANode-> TreeView-> Handle, &tvItem);
return ((BOOL)(tvItem.state > > 12) -1);
}
//----------------------------------------
void TForm1::SetNodeChecked(TTreeNode *ANode,bool IsSetToChecked)
{
TVITEM tvItem;
tvItem.mask = TVIF_HANDLE | TVIF_STATE;
tvItem.hItem = ANode-> ItemId;
tvItem.stateMask = TVIS_STATEIMAGEMASK;
tvItem.state = INDEXTOSTATEIMAGEMASK(IsSetToChecked?2:1);
TreeView_SetItem(ANode-> TreeView-> Handle, &tvItem);
}
//----------------------------------------
void TForm1::SetChildChecked(TTreeNode *ANode,bool yn)
{ // 把它的子孙都置成一样
int count=ANode-> Count;
SetNodeChecked(ANode,yn);
if (count!=0)
for (int i=0;i <count;i++) // 递归
SetChildChecked(ANode-> Item[i],yn);
}
void __fastcall TForm1::TreeView1MouseMove(TObject *Sender,
TShiftState Shift, int X, int Y)
{
ClickNode = TreeView1-> GetNodeAt(X, Y);
if (ClickNode!=NULL) // 保存原节点的Checked值
NodeChecked=GetNodeChecked(ClickNode);
}
//---------------------------------------
void __fastcall TForm1::TreeView1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
if (ClickNode!=NULL)
if (GetNodeChecked(ClickNode)!=NodeChecked)
{ // 把它的子孙都置成一样
NodeChecked=!NodeChecked; // 更新它
SetChildChecked(ClickNode,NodeChecked);
}
}
//---------------------------------------