TreeNodeEventHandler 委托
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示将对 TreeNodeCollapsed 控件的以下事件进行处理的方法:TreeNodeDataBound、TreeNodeExpanded、TreeNodePopulate 或 TreeView。
public delegate void TreeNodeEventHandler(System::Object ^ sender, TreeNodeEventArgs ^ e);
public delegate void TreeNodeEventHandler(object sender, TreeNodeEventArgs e);
type TreeNodeEventHandler = delegate of obj * TreeNodeEventArgs -> unit
Public Delegate Sub TreeNodeEventHandler(sender As Object, e As TreeNodeEventArgs)
参数
- sender
- Object
事件源。
包含事件数据的 TreeNodeEventArgs。
示例
下面的代码示例演示如何使用 TreeNodeEventHandler 委托以编程方式注册事件处理方法。
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
void Page_Load(Object sender, EventArgs e)
{
// Create a new TreeView control.
TreeView NewTree = new TreeView();
// Set the properties of the TreeView control.
NewTree.ID = "BookTreeView";
NewTree.DataSourceID = "BookXmlDataSource";
// Create the tree node binding relationship.
// Create the root node binding.
TreeNodeBinding RootBinding = new TreeNodeBinding();
RootBinding.DataMember = "Book";
RootBinding.TextField = "Title";
// Create the parent node binding.
TreeNodeBinding ParentBinding = new TreeNodeBinding();
ParentBinding.DataMember = "Chapter";
ParentBinding.TextField = "Heading";
// Create the leaf node binding.
TreeNodeBinding LeafBinding = new TreeNodeBinding();
LeafBinding.DataMember = "Section";
LeafBinding.TextField = "Heading";
// Add bindings to the DataBindings collection.
NewTree.DataBindings.Add(RootBinding);
NewTree.DataBindings.Add(ParentBinding);
NewTree.DataBindings.Add(LeafBinding);
// Manually register the event handler for the TreeNodeExpanded event.
NewTree.TreeNodeExpanded += new TreeNodeEventHandler(this.Node_Expand);
// Add the TreeView control to the Controls collection of the PlaceHolder control.
ControlPlaceHolder.Controls.Add(NewTree);
}
void Node_Expand(Object sender, TreeNodeEventArgs e)
{
// Display the expanded node.
Message.Text = "You expanded: " + e.Node.Text;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>TreeView TreeNodeEventHandler Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>TreeView TreeNodeEventHandler Example</h3>
<asp:PlaceHolder id="ControlPlaceHolder" runat="server">
</asp:PlaceHolder>
<asp:XmlDataSource id="BookXmlDataSource"
DataFile="book.xml"
runat="server">
</asp:XmlDataSource>
<br /><br />
<asp:Label id="Message" runat="server"/>
</form>
</body>
</html>
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
' Create a new TreeView control.
Dim NewTree As TreeView = New TreeView
' Set the properties of the TreeView control.
NewTree.ID = "BookTreeView"
NewTree.DataSourceID = "BookXmlDataSource"
' Create the tree node binding relationship.
' Create the root node binding.
Dim RootBinding As TreeNodeBinding = New TreeNodeBinding
RootBinding.DataMember = "Book"
RootBinding.TextField = "Title"
' Create the parent node binding.
Dim ParentBinding As TreeNodeBinding = New TreeNodeBinding
ParentBinding.DataMember = "Chapter"
ParentBinding.TextField = "Heading"
' Create the leaf node binding.
Dim LeafBinding As TreeNodeBinding = New TreeNodeBinding
LeafBinding.DataMember = "Section"
LeafBinding.TextField = "Heading"
' Add bindings to the DataBindings collection.
NewTree.DataBindings.Add(RootBinding)
NewTree.DataBindings.Add(ParentBinding)
NewTree.DataBindings.Add(LeafBinding)
' Manually register the event handler for the TreeNodeExpanded event.
AddHandler NewTree.TreeNodeExpanded, AddressOf Node_Expand
' Add the TreeView control to the Controls collection of the PlaceHolder control.
ControlPlaceHolder.Controls.Add(NewTree)
End Sub
Sub Node_Expand(ByVal sender As Object, ByVal e As TreeNodeEventArgs)
' Display the expanded node.
Message.Text = "You expanded: " & e.Node.Text
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>TreeView TreeNodeEventHandler Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>TreeView TreeNodeEventHandler Example</h3>
<asp:PlaceHolder id="ControlPlaceHolder" runat="server">
</asp:PlaceHolder>
<asp:XmlDataSource id="BookXmlDataSource"
DataFile="book.xml"
runat="server">
</asp:XmlDataSource>
<br /><br />
<asp:Label id="Message" runat="server"/>
</form>
</body>
</html>
注解
创建 TreeNodeEventHandler 委托时,需要标识将处理该事件的方法。 若要将事件与事件处理程序关联,请将该委托的一个实例添加到事件中。 除非移除了该委托,否则每当发生该事件时就会调用事件处理程序。 有关事件处理程序委托的详细信息,请参阅 处理和引发事件。
扩展方法
GetMethodInfo(Delegate) |
获取指示指定委托表示的方法的对象。 |