|
-
Jul 20th, 2007, 01:12 PM
#1
Thread Starter
Addicted Member
Property with Collection (Of RichTextBox)
OK,
I've created a custom Calendar control that works very well. I'm now trying to provide the user a way to load and save the Calendar data. I've chosen to save the data in a Collection (Of RichTextBox).
Here's the Property definition:
Code:
Private m_MonthItemCollection As New Collection(Of RichTextBox)
<Category("Appearance"), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Content), _
Description("Calendar Item Data Collection.")> _
Public Property MonthItemCollection() As Collection(Of RichTextBox)
Get
MonthItemCollection = m_MonthItemCollection
End Get
Set(ByVal value As Collection(Of RichTextBox))
Dim iIndex As Integer
m_MonthItemCollection = value
For iIndex = 1 To m_MonthItemCollection.Count
AssignValuesToCalendar(iIndex)
Next iIndex
End Set
End Property
Here's the initialization of the Collection in New():
Code:
Dim iIndex As Integer
Dim MyRTB As RichTextBox
For iIndex = 0 To 30
MyRTB = New RichTextBox
m_MonthItemCollection.Add(MyRTB)
Next iIndex
and here's the code that assigns the correct RichTextBox to the Collection:
Code:
Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged
Dim iCollectionIndex As Integer
iCollectionIndex = CInt(Val(lblDay1.Text)) - 1
m_MonthItemCollection(iCollectionIndex) = RichTextBox1
End Sub
and here's the code that the user calls to get the data from the control:
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
RichTextBox1 = CalendarControl1.MonthItemCollection(CInt(NumericUpDown1.Text) - 1)
End Sub
If I stop in the Control (i.e. in RichTextBox1_TextChanged), the data looks fine, but when I stop in Button1_Click, there is no text in the collection. Any ideas?
-
Jul 20th, 2007, 06:57 PM
#2
Re: Property with Collection (Of RichTextBox)
You should NOT be serialising a collection of RichTextBoxes. Each RTB containsa string. THAT is what you should be serialising. When you load your collection you can then create the required number of RTBs and load your strings into them.
Also, as I believe a mentioned in one of your previous threads, you should not be declaring a Collection of anything. The Collection(Of T) class is intended to be used as a base class only. Either inherit Collection(Of T) to create your own strongly-typed collection or just use List(Of T).
-
Jul 21st, 2007, 10:03 PM
#3
Thread Starter
Addicted Member
Re: Property with Collection (Of RichTextBox)
jmcilhinney,
That's fine but I don't just want a Text String, I want a richtextbox (i.e. support for colors, pictures, etc. that come with RichTextBox) for each day of the month. I want the user to be able to set the RTB for any date and retrieve the RTB for any date...
Last edited by tim8w; Jul 21st, 2007 at 10:07 PM.
-
Jul 21st, 2007, 10:12 PM
#4
Re: Property with Collection (Of RichTextBox)
When you view a Web page in your browser, what does the Web server send to you? Does it send an entire browser? Of course not. It sends a string containing HTML code. Your browser then interprets that code and displays the result.
The RichTextBox control is the same, although simpler. You read a string containing RTF code. The RichTextBox then interprets that and displays the result. It is THAT string - the one containing the RTF code - that you should be saving, NOT the RichTextBox control. You get that string from the control's Rtf property.
I suggest that you read the documentation for the classes you're using to get a general understanding of how they work. The help topic for the RTB class would have enlightened you.
-
Jul 23rd, 2007, 06:09 PM
#5
Thread Starter
Addicted Member
Re: Property with Collection (Of RichTextBox)
jmcilhinney,
Fine. I still need a Collection of Strings to hold the 31 days worth of rtf info. If I change the code above to use a collection of strings, the results are the same...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|