获取我计算机中项目的路径 [英] get the path of items in my computer

查看:78
本文介绍了获取我计算机中项目的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在清单框中获取任何项目的路径吗?

在我的删除程序中,我想搜索文件/文件夹,然后在我的清单列表中显示它,并想通过标记它来删除需要的内容,然后按Delete键,它将从我的计算机中删除.

我正在使用Microsoft Visual Studio 2008(VC ++)

谢谢

Can i get the path for any item in checkedlistbox ?

In my delete program , I want to search for the file/folder then show it in my checkedlistbox and I want to delete what I need by marking it then press delete and it will delete from my computer ??

I am working on Microsoft Visual Studio 2008 ( VC++)

thanks

推荐答案

在没有标记语言和UI库的情况下问这样的问题是不好的.您不想我们用几种语言来解释它吗?

我假设System.Windows.Forms和C#.

我认为问题在于您没有在System.Windows.Forms.CheckedListBox数据中存储完整的路径名.可能是因为您只想显示文件名而没有完整的路径名或其他.也就是说,问题在于您需要使用具有完整路径名的数据,但是您不想显示此数据.我没听错吗?

您的错误是认为列表中只能包含字符串项目.事实并非如此:您可以添加任何对象.每个项目中显示的内容取决于方法object.ToString返回的内容.重写此方法(您可以这样做,因为这是一个虚拟方法,如果所有类型的对象都是从System.Object派生的),并且您可以在System.Windows.Forms.CheckedListBox的项目中包含所需的任何数据并显示所需的内容:

It''s not nice to ask such questions without tagging language and UI library. Don''t you want us to explain it in several languages?

I''ll assume System.Windows.Forms and C#.

I think the problem is that you don''t store full path name in the System.Windows.Forms.CheckedListBox data. Probably this is because you want to display only file names without full path names, or something else. That is, the problem is that you need to use data with full path names, but you don''t want to display this data. Did I understand it right?

You mistake was to think that you can have only string items in the list. This is not so: you can add any objects. What is displayed in each item depends on what is returned by the method object.ToString. Override this method (you can do it because this is a virtual method available if all object as all types are derived from System.Object) and you can have any data you want in the items of System.Windows.Forms.CheckedListBox and display what you want:

internal class CheckBoxHelper {
   internal CheckBoxHelper(string pathName) { this.fPathName = pathName; }
   internal string PathName { get { return fPathName } }
   public override string ToString {
       return System.IO.Path.GetFileName() { return this.fPathName; }
   }
   string fPathName;
}



代替流项目,添加类型为CheckBoxHelper的项目.当您需要使用列表项表示的文件时,将其键入到CheckBoxHelper并使用实例属性CheckBoxHelper.PathName读取完整路径名.

—SA



Instead stream items, add items of the type CheckBoxHelper. When you need to work with the file represented by the list item, type-cast it to CheckBoxHelper and use instance property CheckBoxHelper.PathName to read the full path name.

—SA


这篇关于获取我计算机中项目的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆