i have a structure element in my code which looks like
Code:
Public Structure EventItem
Dim Start As Date
Dim Finish As Date
Dim Duration As Date
Dim Subject As String
Dim Tag As String
Dim EventColor As Color
Dim EventNo As Integer
Dim TotalEventsOnDay As Integer
End Structure
you would have to write a method that would enumerate the list, and count that information.
If you would need to do this often, I would suggest writing a class that inherits from list, so that you can encapsulate that method in the class itself, and call it whenever needed from your code.
you would have to write a method that would enumerate the list, and count that information.
If you would need to do this often, I would suggest writing a class that inherits from list, so that you can encapsulate that method in the class itself, and call it whenever needed from your code.
Thanks kleinma
do you know any code sample where i can see how i archive this?
First of all I would suggest using a class rather than a structure. I would also suggest making all those fields private and exposing them through public properties. Properties are preferable to fields for various reasons, not least of which is the fact that you cannot use fields in data binding.
Whether you choose to accept that advice or not, your collection could look something like this:
There's not much to mess up. You've already got the code for the collection. If you want to take my advice with regards to the EventItem type then it would look like this:
vb Code:
Public Class EventItem
Private _start As Date
Public Property Start() As Date
Get
Return _start
End Get
Set(ByVal value As Date)
_start = value
End Set
End Property
End Class
That's for changing the Structure to a Class and the Start field to a property. All the other fields would be handled similarly.
I did this and I created a class DayItem, EventItem and EventItemCollection. And Impotet them into the Monthview class, but it looks like now the list is not holding the different items only the last
I haven't looked at your attachment and I'm not going to. Just note that structures are value types and classes are reference types. If you create a structure instance and add it to a collection 10 times, changing the property values each time then you'll end up with 10 different structure instances in the collection. That's because each time you are adding a copy of the structure to the collection. If you do the same thing with a class you'll get a totally different result. The collection will contain 10 references all to the same class instance and it will only contain the last property values you set. If you want 10 class instances then you have to create 10 distinct instances, i.e. use the New keyword 10 times.
OK now I understand my mistake - i declared on top of the methode
Dim ItemSquare as new DayItem - but I needed it to do in the loop where the 42 different ItemSquares are been filled and putet into the list.
Ok one major Problem solved many thanks - Manfred