Insert Controls at Runtime to RadGroupBox

3 posts, 1 answers
  1. Marc
    Marc avatar
    15 posts
    Member since:
    Apr 2013

    Posted 12 Jun 2014 Link to this post

    Hi there,

    i want to add some Control fields to my RadGroupBox.

    The Admin can change the fields in a form which a regular user can see.

    These fields are saved in a database. 

    So i added a empty RadGroupBox to my control with the following changed settings:

    AutoSize = True
    Visible = False

    I found an example in the forum but that didn't work for me:

    Using dataContext = New DataContext()
                Dim fields = dataContext.tblDynamicFields.Where(Function(x) x.PageID = 1 And x.Active = True)
                If fields.Count > 0 Then
                    Me.DynamicFieldGroupBox.Visible = True
                End If

                For Each field In fields
                    Dim label = New RadLabel
                    label.Text = field.Name
                    Me.DynamicFieldGroupBox.Controls.Add(New RadTextBox)
    End Using

    I currently have 3 Fields in my table, and they are all loaded from the datacontext.

    The visibility is fine. The GroupBox is shown, but the Elements i have added are all stacked together. I have attached a picture showing my problem

    Thanks a lot

  2. Answer
    Dimitar avatar
    1321 posts

    Posted 17 Jun 2014 Link to this post

    Hi Marc,

    Thank you for writing.

    In this case you should set a location for the controls, this is needed because as you can see their default location is (0,0) and they are positioned at the top left corner of the group box. For example you can initialize the controls as follows:
    radGroupBox1.Visible = True
    Dim label As New RadLabel()
    label.Text = "Label"
    label.Location = New Point(10, 20)
    Dim textbox As New RadTextBox()
    textbox.Width = 100
    textbox.Location = New Point(label.Size.Width, 20)

    Please let me know if there is something else I can help you with. 
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
  3. DevCraft R3 2016 release webinar banner
  4. Marc
    Marc avatar
    15 posts
    Member since:
    Apr 2013

    Posted 26 Jun 2014 in reply to Dimitar Link to this post

    Thanks a lot,

    worked liek a charm
Back to Top