New to Telerik UI for WinFormsStart a free 30-day trial

Programmatically Arrange Items

Updated over 6 months ago

Items in RadDataEntry can be arranged both at design time and run time. At design time users can use the designer to arrange the items according to their needs by drag and drop or by setting the desired properties of the items. However at run time there is no designer that can be used to arrange them, so to achieve the desired layout the user should use the exposed events or to access the controls from the Controls collection and to change their location, size and etc. The following example will demonstrate how to use the control events to arrange the generated items.

1. For the purpose of this tutorial, we will create a new class Employee with a couple of exposed properties. By binding RadDataEntry to object from this type we will generate several items.

Data Object

C#
private class Employee
{
    public string FirstName
    {
        get;
        set;
    }
    public string LastName
    {
        get;
        set;
    }
    public string Occupation
    {
        get;
        set;
    }
    public DateTime StartingDate
    {
        get;
        set;
    }
    public bool IsMarried
    {
        get;
        set;
    }
    public int Salary
    {
        get;
        set;
    }
    public Gender Gender
    {
        get;
        set;
    }
}
private enum Gender
{
    Female,
    Male
}

Data Binding

C#
this.radDataEntry1.DataSource = new Employee() 
{ 
    FirstName = "Sarah",
    LastName = "Blake",
    Occupation = "Supplied Manager", 
    StartingDate = new DateTime(2005, 04, 12),
    IsMarried = true, 
    Salary = 3500, Gender = Gender.Female 
};

Figure 1: RadDataEntry is initialized.

WinForms RadDataEntry Is Initialized

2. To arrange the items we will subscribe to the ItemInitialized event of RadDataEntry. This event is triggered when an item is initialized, so it is suitable to introduce changes.

Special Arrangement

C#
void radDataEntry1_ItemInitialized(object sender, Telerik.WinControls.UI.ItemInitializedEventArgs e)
{
    if (e.Panel.Controls[1].Text == "FirstName")
    {
        e.Panel.Size = new Size(150, 25);
        e.Panel.Controls[1].Text = "Name";
    }
    else if (e.Panel.Controls[1].Text == "LastName")
    {
        e.Panel.Size = new Size(100, 25);
        e.Panel.Controls[1].Visible = false;
        e.Panel.Location = new Point(160, radDataEntry1.ItemSpace);
    }
    else
    {
        e.Panel.Location = new Point(e.Panel.Location.X, e.Panel.Location.Y - 25);
    }
}

Figure 2: The whole name is now displayed in the first row.

WinForms RadDataEntry The whole name is now displayed in the first row

See Also

In this article
See Also
Not finding the help you need?
Contact Support