CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2004
    Posts
    239

    [RESOLVED] Need a way to store and retrieve 31 Strings in a Property

    Since I haven't had much luck solving this problem myself, I'd thought I'd throw out what I'm trying to solve and see if someone has another way of doing what I want.

    I have a CustomCalendar control. It contains 31 RichTextBoxes (one for each day of the month) where data can be entered during run time. I would like to have a Property where this information can be loaded and retrieved by the programmer.

    As I mentioned above, I have tried a Collection of RichTextBox and a Collection of Strings and neither worked. Has anyone done anything similar?

  2. #2
    Join Date
    Apr 2002
    Location
    PA, USA
    Posts
    1,658

    Re: Need a way to store and retrieve 31 Strings in a Property

    A collection of strings, either List(of string) or the likes, should work just fine. You can further restrict it by making your collection string[31] if you want.

    on data bind, load the strings from the string collection into the rich text box's.

    Don't make the mistake of assuming that it should auto data bind because you've set a string. Stick to the model laid out by other .NET controls and you'll be fine: set the DataSource (in this case, just setting up the string collection property) and then call DataBind() and have your already-created controls load in their data from your data source.

    cheers!
    -eli

    Edit: I didn't look at what board we were in before posting and posted some C#
    =--=--=--=--=--=--=--=--=--=--=--=--=--=
    Please rate this post to show your appreciation for those that helped you.

    Before You Post A Question, Please Read This: How & When To Ask Your Question
    =--=--=--=--=--=--=--=--=--=--=--=--=--=

    -eli
    http://www.toad-software.com
    http://www.dailymission.com - Do It Daily

  3. #3
    Join Date
    Nov 2004
    Posts
    239

    Smile Resolved: Need a way to store and retrieve 31 Strings in a Property

    I ended up throwing out the Collection idea and settling for a simple DateText Property. Works great!

    Code:
        <Category("Appearance"), DefaultValue(""), _
        DesignerSerializationVisibility(DesignerSerializationVisibility.Content), _
        Description("Calendar Day Text.")> _
        Public Property DayText(ByVal iIndex As Integer) As RichTextBox
            Get
                Dim iPanelControlIndex, iControlIndex As Integer
    
                ' RichTextBoxes are contained within a SplitContainer control which is contained within a TableLayoutPanel control
                DayText = Nothing
                For iPanelControlIndex = 0 To Me.TableLayoutPanel1.Controls.Count - 1
                    iControlIndex = 0
                    While iControlIndex < Me.TableLayoutPanel1.Controls(iPanelControlIndex).Controls.Count
                        If Me.TableLayoutPanel1.Controls(iPanelControlIndex).Controls(iControlIndex).Controls(0).Tag = iIndex Then
                            DayText = Me.TableLayoutPanel1.Controls(iPanelControlIndex).Controls(iControlIndex).Controls(0)
                            Exit For
                        Else
                            iControlIndex = iControlIndex + 1
                        End If
                    End While
                Next iPanelControlIndex
            End Get
    
            Set(ByVal value As RichTextBox)
                Dim iPanelControlIndex, iControlIndex As Integer
    
                ' RichTextBoxes are contained within a SplitContainer control which is contained within a TableLayoutPanel control
                m_MonthItem = Nothing
                For iPanelControlIndex = 0 To Me.TableLayoutPanel1.Controls.Count - 1
                    iControlIndex = 0
                    While iControlIndex < Me.TableLayoutPanel1.Controls(iPanelControlIndex).Controls.Count
                        If Me.TableLayoutPanel1.Controls(iPanelControlIndex).Controls(iControlIndex).Controls(0).Tag = iIndex Then
                            m_MonthItem = Me.TableLayoutPanel1.Controls(iPanelControlIndex).Controls(iControlIndex).Controls(0)
                            Exit For
                        Else
                            iControlIndex = iControlIndex + 1
                        End If
                    End While
                Next iPanelControlIndex
                m_MonthItem = value
            End Set
        End Property

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured