none
How to put a richtextboxes in a For next Loop RRS feed

  • Question

  • Hello,

    I want to make my code a bit smaller so I programmed it like below, in this way it does not accept my richtexbox, Is there a way how to put this Richtexbox in a loop by using this i2 integer

     

    Dimi1 AsInteger


    Dimi2 AsInteger


           

    Dimi3 AsInteger


           

    Fori1 = 0 To7

                i2 = i1 + 1

                i3 = 9 + i1

                RichTextBoxi2.Text =

    m_DataTable.Rows(i1)(

    "BuroNamen").ToString()

                RichTextBoxi3.Text =

    m_DataTable.Rows(i1)(

    "BuroMail").ToString()

     

           

    Next

    • Moved by 宝宝徐 Monday, October 30, 2017 6:53 AM
    Saturday, October 28, 2017 11:16 AM

All replies

  • Hi Ferry,

    Thank you for posting in MSDN forum.

    This forum is about Visual Studio WPF/SL Designer, Visual Studio Guidance Automation Toolkit, Developer Documentation and Help System, and Visual Studio Editor. From your description, this issue is much related to the project migrating, I help you move to VB forum to get a better professional support.

    Thank you for your understanding and cooperation.

    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, October 30, 2017 6:47 AM
  • I want to make my code a bit smaller so I programmed it like below, in this way it does not accept my richtexbox, Is there a way how to put this Richtexbox in a loop by using this i2 integer

    You need to create a collection for the rich text boxes, and add each one to the collection in the correct sequence.  Then you can refer to them by the index using the collection.

    Dim RichTextBoxes As New List(Of RichTextBox)
    RichTextBoxes.Add(RichTextBox1) RichTextBoxes.Add(RichTextBox2) RichTextBoxes.Add(RichTextBox3) RichTextBoxes.Add(RichTextBox4) ' and so on ... Dim i1 As Integer Dim i2 As Integer Dim i3 As Integer For i1 = 0 To 7 i2 = i1 + 1 i3 = 9 + i1 RichTextBoxes(i2).Text = m_DataTable.Rows(i1) ("BuroNamen").ToString() RichTextBoxes(i3).Text = m_DataTable.Rows(i1) ("BuroMail").ToString() Next

    Monday, October 30, 2017 7:29 AM
  • Hi  ferry1995,

    According to your description, I guess that you have 16 RichTextBox controls in the form, and you want to add m_DataTable.Rows(0-7)("BuroNamen").ToString() into 8 RichTextBox controls, and add m_DataTable.Rows(0-7)("BuroMail").ToString() into 8 richTextBox controls, Am I right? If yes, you can add 8 Richtextbox control into GroupBox1 control, and then add another RichTextBox controls into GroupBox2, then loop control in Richtextbox, if the control is Richtextbox, you can add data.

     Dim dt As New DataTable
            dt.Columns.Add("BuroNamen", GetType(String))
            dt.Columns.Add("BuroMail", GetType(String))
            dt.Rows.Add("A", "AA")
            dt.Rows.Add("B", "BB")
            dt.Rows.Add("C", "CC")
            dt.Rows.Add("D", "DD")
            dt.Rows.Add("E", "EE")
            dt.Rows.Add("F", "FF")
            dt.Rows.Add("G", "GG")
            dt.Rows.Add("H", "AHH")
            Dim i As Integer = 0
            While i < 8
    
                For Each richtext As Control In GroupBox1.Controls
                    If richtext.GetType Is GetType(RichTextBox) Then
                        DirectCast(richtext, RichTextBox).AppendText(dt.Rows(i)("BuroNamen").ToString())
                        i = i + 1
                    End If
                Next
            End While
            Dim j As Integer = 0
            While j < 8
    
                For Each richtext As Control In GroupBox2.Controls
                    If richtext.GetType Is GetType(RichTextBox) Then
    
                        DirectCast(richtext, RichTextBox).AppendText(dt.Rows(j)("BuroMail").ToString())
                        j = j + 1
                    End If
                Next
            End While
    

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, October 30, 2017 7:49 AM
    Moderator
  • Hi Ferry,

    Default are given in this forum almost forever replies as if VB is still limited of what was in antique VB (Windows Forms).

    Because of the forum you visited I assume your question is however WPF

    Can you tell us that, because then non of the current given replies fits

    https://msdn.microsoft.com/en-us/library/system.windows.controls.richtextbox(v=vs.110).aspx


    Success
    Cor

    Monday, October 30, 2017 4:23 PM