Click here to Skip to main content
15,912,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 13-May-11 3:33am
v2
Comments
ZeeroC00l 13-May-11 9:34am    
-- edited for typo and Format

BR//
Harsha
Sergey Alexandrovich Kryukov 13-May-11 12:04pm    
Tag it! Forms? How about language? C#?
--SA

1 solution

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:

C#
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;
}


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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900