jbaisden
asked on
easy CheckedListBox question using vb .net 2005
Okay guys this is pretty easy, yet I simply am not sure what to search to find the answer. I have a checked list box. I want it to work kind of like a drop down list where you can have a text field that is displayed and a value field that is the actual value used.
In my checked list box, I am adding a list of files in a given directory. I created a sloppy class to test the above and I'm not getting the results expected.
files = Directory.GetFiles(fldrdlg
For Each strFile In files
chk.fullfile = strFile
chk.shortfile = strFile.Substring(strFile.
chklbTargetFiles.Items.Add
chk = New chunk
Next
All of this is in the Form1 class. So is the following definiton for the class chunk:
Private Class chunk
Public fullfile As String
Public shortfile As String
End Class
Like I said, this was just meant to be quick and dirty. I am trying to display the shortfile attribute of chunk in the checkedlistbox. When I get the items that are selected, I want to the attribute fullfile from the chunk object stored for the given item(s).
When the program runs the text displayed for each item added is: FileCopier.Form1 + chunk
Am I missing something small or just barking up the wrong tree with this?
ASKER
What would also help is a good reference point for how to use the CheckedListBox class. I've primarily done Web programming, so I'm just getting into the windows forms environment. I had expected the items stored in this control to work more like a datagriditem or something, but it seems really difficult to access a single item in this control. I'm trying to access an object at a given index in the object collection so I can adjust the checked property/attribute (If this event exists).
I'm just really confused and badly need a reference point that is more clear than the class documentation for the CheckedListBox class.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yep that did it. I was just missing the:
Public Overrides Function ToString() As String
Return Me.ShortFile
End Function
Once I added that, everything was fine.
ASKER
This is a vb .net Windows application in VS 2005 by the way.