This is a migrated thread and some comments may be shown as answers.

Insert Controls at Runtime to RadGroupBox

2 Answers 71 Views
GroupBox
This is a migrated thread and some comments may be shown as answers.
Dk
Top achievements
Rank 1
Dk asked on 12 Jun 2014, 03:01 PM
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
            Else
                Return
            End If

            For Each field In fields
                Dim label = New RadLabel
                label.Text = field.Name
                Me.DynamicFieldGroupBox.Controls.Add(label)
                Me.DynamicFieldGroupBox.Controls.Add(New RadTextBox)
            Next
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 Answers, 1 is accepted

Sort by
0
Accepted
Dimitar
Telerik team
answered on 17 Jun 2014, 09:33 AM
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)
 
radGroupBox1.Controls.Add(label)
radGroupBox1.Controls.Add(textbox)

Please let me know if there is something else I can help you with. 
 
Regards,
Dimitar
Telerik
 
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.
 
0
Dk
Top achievements
Rank 1
answered on 26 Jun 2014, 12:06 PM
Thanks a lot,

worked liek a charm
Tags
GroupBox
Asked by
Dk
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Dk
Top achievements
Rank 1
Share this question
or