Using collections to add sub procedures to class properties
Posted on 2005-04-26
I've been encountering some difficulties describing my question and with the responses I have (and haven't) been getting, so I'm askng this question again, another way, hoping to elicit more, constructive responses. Hopefully this time I've communicated my problem clearly enough. Here it is:
I have a class with an property that is a string array (named FileNames) for storing filenames. As my code is now, I instantiate the class (as ProjectName, for example) in a form and add filenames to the class' FileNames array by using:
ReDim Preserve ProjectName.FileNames(ProjectName.FileNames.Length)
ProjectName.FileNames(ProjectName.FileNames.Length - 1) = "new filename to add"
This works fine, but I'd rather the class itself handle additions and removals to the list of filenames it stores. Instead of using ReDim, I'd like to interact with the class from my form the same way ListView and other controls are used. For example, to add and remove a filename, I'd like to use:
ProjectName.FileNames.Add("new filename to add")
I don't know how to do this though. I believe this requires somehow using collections, but, as a self-taught VB4 - 6 programmer trying to learn .NET, I haven't encountered collections before, and my Googling efforts haven't turned anything up. Could someone please tell me how to accomplish this?
- Chris O.