在C++中,CListCtrl有个方法叫SetItemData,这样我就可以把自定义的class和某个item绑定,在C#中的listview有类似的方法吗?或者通过某种方法也可以达到这样的效果
解决方案 »
- C#应用程序安装部署问题(急,在线等待)
- 如何在C#程序中控制VS2008开发环境
- 请问怎么转换win32_process中的属性creationDate为c#中的datetime类型
- 【请教】哪位了解ASP.Net的控件SqlDataSource,其中的Filter功能使用时候有些问题
- vs2008开发的软件怎么连接sql2000
- 继承控件的一个问题
- 用WINFORM写的程序大家都怎么布局的,发现1024下面的布局到800*600下面全错位了,怎样才能不变形呢!
- GridView~~~~显示问题
- 帮帮小弟一个忙啊,很急的
- 急!!,请各位帮忙!! -- 无法在WEB服务器上启动测试
- 动态生成多个label
- C#程序連接db2數據庫驅動問題。。在數據庫版有高分求救。。。
创建一个从 TreeNode 类派生的新节点类,此新节点类具有一个记录文件路径的自定义字段。 Visual Basic 复制代码
Class myTreeNode
Inherits TreeNode Public FilePath As String Sub New(ByVal fp As String)
MyBase.New()
FilePath = fp
Me.Text = fp.Substring(fp.LastIndexOf("\"))
End Sub
End Class
C# 复制代码
class myTreeNode : TreeNode
{
public string FilePath; public myTreeNode(string fp)
{
FilePath = fp;
this.Text = fp.Substring(fp.LastIndexOf("\\"));
}
}
C++ 复制代码
ref class myTreeNode : public TreeNode
{
public:
System::String ^ FilePath; myTreeNode(System::String ^ fp)
{
FilePath = fp;
this->Text = fp->Substring(fp->LastIndexOf("\\"));
}
};
使用派生的树节点
新的派生树节点可用作函数调用的参数。 在下面的示例中,文本文件位置的路径设置是 My Documents 文件夹。这样做是因为假定大多数运行 Windows 操作系统的计算机都包含此目录。这还将允许具有最低系统访问级别的用户安全地运行应用程序。 Visual Basic 复制代码
' You should replace the bold text file
' in the sample below with a text file of your own choosing.
TreeView1.Nodes.Add(New myTreeNode (System.Environment.GetFolderPath _
(System.Environment.SpecialFolder.Personal) _
& "\ TextFile.txt ") )
C# 复制代码
// You should replace the bold text file
// in the sample below with a text file of your own choosing.
// Note the escape character used (@) when specifying the path.
treeView1.Nodes.Add(new myTreeNode (System.Environment.GetFolderPath _
(System.Environment.SpecialFolder.Personal) _
+ @"\TextFile.txt") );
C++ 复制代码
// You should replace the bold text file
// in the sample below with a text file of your own choosing.
treeView1->Nodes->Add(new myTreeNode(String::Concat(
System::Environment::GetFolderPath
(System::Environment::SpecialFolder::Personal),
"\\TextFile.txt")));
如果传递了这个树节点,且它的类型被声明为 TreeNode 类,则需要将其强制转换为派生类。类型转换是从一种对象类型到另一种对象类型的显式转换。有关强制转换的更多信息,请参见隐式转换和显式转换 (Visual Basic)、() 运算符(C# 参考)(Visual C#) 或 Cast Operator: () (Visual C++)。 Visual Basic 复制代码
Public Sub TreeView1_AfterSelect(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
Dim mynode As myTreeNode
mynode = CType(e.node, myTreeNode)
MessageBox.Show("Node selected is " & mynode.filepath)
End Sub
C# 复制代码
protected void treeView1_AfterSelect (object sender,
System.Windows.Forms.TreeViewEventArgs e)
{
myTreeNode myNode = (myTreeNode)e.Node;
MessageBox.Show("Node selected is " + myNode.FilePath);
}
....
item.tag=对象;