Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WPF treeview项目类型变量_Wpf_Vb.net_Autocad - Fatal编程技术网

WPF treeview项目类型变量

WPF treeview项目类型变量,wpf,vb.net,autocad,Wpf,Vb.net,Autocad,我正在autocad API中使用WPF类型用户控件 将新节点设置为System.Windows.Controls.TreeViewItem newnode=mypalette2.treeview1.Items.Add(e.DBObject.GetType().ToString()) 但它给出错误“整型值不能转换为treviewitem” 请帮忙 Add()返回将项添加到“Items”集合的索引,而不是TreeViewItem对象本身。使用索引从Items集合中获取TreeViewItem: 未

我正在autocad API中使用WPF类型用户控件

将新节点设置为System.Windows.Controls.TreeViewItem newnode=mypalette2.treeview1.Items.Add(e.DBObject.GetType().ToString())

但它给出错误“整型值不能转换为treviewitem”

请帮忙

Add()返回将项添加到“Items”集合的索引,而不是TreeViewItem对象本身。使用索引从Items集合中获取TreeViewItem:

未经测试的代码,但应该这样做(不要这样编写-使其更干净;):

理想情况下,您应该首先检查以确保Add()没有返回-1,这意味着Add操作失败。

我更喜欢:

Dim newNode As New TreeNode
newNode.Text = e.DBObject.GetType().Name
newNode.Tag = e.DBObject.ObjectId
_treeView.Nodes.Add(newNode)
并且建议您使用实体的ObjectId设置Tag属性,否则您以后无法在代码中引用此项(在树状视图中)

Dim newNode As New TreeNode
newNode.Text = e.DBObject.GetType().Name
newNode.Tag = e.DBObject.ObjectId
_treeView.Nodes.Add(newNode)