[StructLayout(LayoutKind.Sequential, Pack=1)] public struct TV_HITTESTINFO { /// <summary>Client coordinates of the point to test.</summary> public Point pt; /// <summary>Variable that receives information about the results of a hit test.</summary> public TVHit flags; /// <summary>Handle to the item that occupies the point.</summary> }/// <summary>Hit tests for tree view</summary> [Flags] public enum TVHit { /// <summary>In the client area, but below the last item.</summary> NoWhere = 0x0001, /// <summary>On the bitmap associated with an item.</summary> OnItemIcon = 0x0002, /// <summary>On the label (string) associated with an item.</summary> OnItemLabel = 0x0004, /// <summary>In the indentation associated with an item.</summary> OnItemIndent = 0x0008, /// <summary>On the button associated with an item.</summary> OnItemButton = 0x0010, /// <summary>In the area to the right of an item. </summary> OnItemRight = 0x0020, /// <summary>On the state icon for a tree-view item that is in a user-defined state.</summary> OnItemStateIcon = 0x0040, /// <summary>On the bitmap or label associated with an item. </summary> OnItem = (OnItemIcon | OnItemLabel | OnItemStateIcon), /// <summary>Above the client area. </summary> Above = 0x0100, /// <summary>Below the client area.</summary> Below = 0x0200, /// <summary>To the right of the client area.</summary> ToRight = 0x0400, /// <summary>To the left of the client area.</summary> ToLeft = 0x0800 }TV_HITTESTINFO 和 TVHit是系统定义的,还是自己定义的?
今天查了N多资料,有一些进展。谁知道是用setwindowlog还是setitem?还有那些结构,例如TV_ITEM的值应该怎么给啊?能不能解释一下那些值的含义?/// <summary></summary> [DllImport("user32.dll", CharSet=CharSet.Auto)] private static extern int SendMessage(IntPtr hWnd, TreeViewMessages msg, int wParam, ref TV_ITEM lParam);[StructLayout(LayoutKind.Sequential, Pack=1)] public struct TV_ITEM { public uint mask; //结构成员有效性屏蔽位 public IntPtr hItem; //数据项控制句柄 public uint state; //数据项状态 public uint stateMask; //状态有效性屏蔽位 public string pszText; //数据项名称字符串 public int cchTextMax; //数据项名称的最大长度 public int iImage; //数据项图标索引号 public int iSelectedImage; //选中数据项图标索引号 public int cChildren; //子项标识 public uint lParam; //程序定义的32位数据 }private void DrawCheckBox(TreeNode Node) { TV_ITEM tvi = new TV_ITEM(); tvi.state = 0xF000; tvi.hItem = Node.Handle; tvi.mask = 0x18; tvi.iImage = 0x0000; SendMessage(Node.TreeView.Handle,TreeViewMessages.TVM_SETITEM,0,ref tvi); }我不知道tvi的值应该怎么给?是不是这样就可以添加checkbox了? 那位大哥指点一下啊?搞了N天了,很郁闷。
Node没有checkBox属性啊?
to :JasonHeung
如何画?能不能具体点?
Node没有checkBox属性啊?
to :JasonHeung
如何画?能不能具体点?
to :WTaoboy
Node没有checkBox属性啊?
to :JasonHeung
如何画?能不能具体点?
to :WTaoboy
Node没有checkBox属性啊?
to :JasonHeung
如何画?能不能具体点?
to :WTaoboy
Node没有checkBox属性啊?
to :JasonHeung
如何画?能不能具体点?
to :WTaoboy
Node没有checkBox属性啊?
to :JasonHeung
如何画?能不能具体点?
to :WTaoboy
Node没有checkBox属性啊?
to :JasonHeung
如何画?能不能具体点?
to :WTaoboy
Node没有checkBox属性啊?
to :JasonHeung
如何画?能不能具体点?
主要是因为它是将windows控件封装实现的,而不是完全用C#写成的,
对于楼主的需求,基本需要重写TreeView,codeproject上有一个重写TreeView的例子,
很nb的例子,包括背景图片,背景渐变色,树线的颜色样式等等,
可以去参考一下
public struct TV_HITTESTINFO
{
/// <summary>Client coordinates of the point to test.</summary>
public Point pt;
/// <summary>Variable that receives information about the results of a hit test.</summary>
public TVHit flags;
/// <summary>Handle to the item that occupies the point.</summary>
}/// <summary>Hit tests for tree view</summary>
[Flags]
public enum TVHit
{
/// <summary>In the client area, but below the last item.</summary>
NoWhere = 0x0001,
/// <summary>On the bitmap associated with an item.</summary>
OnItemIcon = 0x0002,
/// <summary>On the label (string) associated with an item.</summary>
OnItemLabel = 0x0004,
/// <summary>In the indentation associated with an item.</summary>
OnItemIndent = 0x0008,
/// <summary>On the button associated with an item.</summary>
OnItemButton = 0x0010,
/// <summary>In the area to the right of an item. </summary>
OnItemRight = 0x0020,
/// <summary>On the state icon for a tree-view item that is in a user-defined state.</summary>
OnItemStateIcon = 0x0040,
/// <summary>On the bitmap or label associated with an item. </summary>
OnItem = (OnItemIcon | OnItemLabel | OnItemStateIcon),
/// <summary>Above the client area. </summary>
Above = 0x0100,
/// <summary>Below the client area.</summary>
Below = 0x0200,
/// <summary>To the right of the client area.</summary>
ToRight = 0x0400,
/// <summary>To the left of the client area.</summary>
ToLeft = 0x0800
}TV_HITTESTINFO 和 TVHit是系统定义的,还是自己定义的?
this.treeView1.CheckBoxes =true;???
能不能看清楚再回帖啊?
[DllImport("user32.dll", CharSet=CharSet.Auto)]
private static extern int SendMessage(IntPtr hWnd, TreeViewMessages msg, int wParam, ref TV_ITEM lParam);[StructLayout(LayoutKind.Sequential, Pack=1)]
public struct TV_ITEM
{
public uint mask; //结构成员有效性屏蔽位
public IntPtr hItem; //数据项控制句柄
public uint state; //数据项状态
public uint stateMask; //状态有效性屏蔽位
public string pszText; //数据项名称字符串
public int cchTextMax; //数据项名称的最大长度
public int iImage; //数据项图标索引号
public int iSelectedImage; //选中数据项图标索引号
public int cChildren; //子项标识
public uint lParam; //程序定义的32位数据
}private void DrawCheckBox(TreeNode Node)
{
TV_ITEM tvi = new TV_ITEM();
tvi.state = 0xF000;
tvi.hItem = Node.Handle;
tvi.mask = 0x18;
tvi.iImage = 0x0000; SendMessage(Node.TreeView.Handle,TreeViewMessages.TVM_SETITEM,0,ref tvi);
}我不知道tvi的值应该怎么给?是不是这样就可以添加checkbox了?
那位大哥指点一下啊?搞了N天了,很郁闷。
关键字 TreeView CheckBox javascript
出处
最近在论坛上回答了一些关于客户端操作TreeView节点选中的问题,在网友提供的代码基础上做了两个例子。可惜原贴已经丢失了,整理一下写成文档吧
为了书写方便,这两个例子没有采用codebehind方式,复制即可运行第一个例子是当取消或选中节点选中状态时,子节点也做相应的取消或选中变化
需要注意的是如果要初始设置TreeNode为选中状态,只能在客户端设置。如果在服务器端设置TreeNode为选中状态,则在客户端使用getAttribute("Checked"),得到的值永远是true。<%@ Register TagPrefix="iewc" Namespace="Microsoft.Web.UI.WebControls" Assembly="Microsoft.Web.UI.WebControls, Version=1.0.2.226, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<HTML>
<HEAD>
<script language="C#" runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
TreeView1.Attributes.Add("oncheck","tree_oncheck(this)");
}
</script>
<script language="javascript">
<!--
//初始化选中节点
function initchecknode()
{
var node=TreeView1.getTreeNode("1");
node.setAttribute("Checked","true");
setcheck(node,"true");
FindCheckedFromNode(TreeView1);
}
//oncheck事件
function tree_oncheck(tree)
{
var node=tree.getTreeNode(tree.clickedNodeIndex);
var Pchecked=tree.getTreeNode(tree.clickedNodeIndex).getAttribute("checked");
setcheck(node,Pchecked);
document.all.checked.value="";
document.all.unchecked.value="";
FindCheckedFromNode(TreeView1);
}
//设置子节点选中
function setcheck(node,Pc)
{
var i;
var ChildNode=new Array();
ChildNode=node.getChildren();
if(parseInt(ChildNode.length)==0)
return;
else
{
for(i=0;i<ChildNode.length;i++)
{
var cNode;
cNode=ChildNode[i];
if(parseInt(cNode.getChildren().length)!=0)
setcheck(cNode,Pc);
cNode.setAttribute("Checked",Pc);
}
}
}
//获取所有节点状态
function FindCheckedFromNode(node) {
var i = 0;
var nodes = new Array();
nodes = node.getChildren();
for (i = 0; i < nodes.length; i++) {
var cNode;
cNode=nodes[i];
if (cNode.getAttribute("Checked"))
AddChecked(cNode);
else
AddUnChecked(cNode);
if (parseInt(cNode.getChildren().length) != 0 ) {
FindCheckedFromNode(cNode);
}
}
}
//添加选中节点
function AddChecked(node) {
document.all.checked.value += node.getAttribute("NodeData");
document.all.checked.value += ',';
}
//添加未选中节点
function AddUnChecked(node) {
document.all.unchecked.value += node.getAttribute("NodeData");
document.all.unchecked.value += ',';
}
//-->
</script>
</HEAD>
<body onload="initchecknode()">
<iewc:TreeView id="TreeView1" runat="server" ExpandLevel="5">
<iewc:TreeNode NodeData="0" CheckBox="True" Text="Node0" Expanded="True">
<iewc:TreeNode NodeData="1" CheckBox="True" Text="Node1" Expanded="True"></iewc:TreeNode>
<iewc:TreeNode NodeData="2" CheckBox="True" Text="Node2" Expanded="True">
<iewc:TreeNode NodeData="3" CheckBox="True" Text="Node3" Expanded="True">
<iewc:TreeNode NodeData="4" CheckBox="True" Text="Node4" Expanded="True"></iewc:TreeNode>
</iewc:TreeNode>
</iewc:TreeNode>
</iewc:TreeNode>
<iewc:TreeNode NodeData="5" CheckBox="True" Text="Node5" Expanded="True">
<iewc:TreeNode NodeData="6" CheckBox="True" Text="Node6" Expanded="True"></iewc:TreeNode>
</iewc:TreeNode>
<iewc:TreeNode NodeData="7" CheckBox="True" Text="Node7" Expanded="True">
<iewc:TreeNode NodeData="8" CheckBox="True" Text="Node8" Expanded="True">
<iewc:TreeNode NodeData="9" CheckBox="True" Text="Node9" Expanded="True"></iewc:TreeNode>
</iewc:TreeNode>
</iewc:TreeNode>
</iewc:TreeView><P>
<TABLE id="Table1" cellSpacing="1" cellPadding="1" width="300" border="1">
<TR>
<TD>
<asp:Label id="Label1" runat="server">checked</asp:Label></TD>
<TD>
<INPUT id="checked" type="text" size="32"></TD>
</TR>
<TR>
<TD>
<asp:Label id="Label2" runat="server">unchecked</asp:Label></TD>
<TD><INPUT id="unchecked" type="text" size="32"></TD>
</TR>
</TABLE>
<br/>
</P>
</body>
</HTML>
loNode.Checked=true;
this.treeView1.Nodes.Add(loNode);
loNode.Checked=true;
this.treeView1.Nodes.Add(loNode);
this.treeView1.CheckBoxes=true;
不是整棵树的节点都有checkbox,是部分节点有!