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