4 Answers, 1 is accepted
You need to set the TextPosition property as well, for example you can use the ItemInitializing event for this:
private void RadDataLayout1_ItemInitializing(object sender, DataLayoutItemInitializingEventArgs e)
{
e.Item.TextPosition = LayoutItemTextPosition.Top;
e.Item.TextAlignment = ContentAlignment.MiddleCenter;
}
I hope this helps. Should you have any other questions, do not hesitate to ask.
Regards,
Dimitar
Progress Telerik
Thank you for the response. When I try this, the text isn't drawn properly above the control.
Complete example:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TestInterfaceDisplayName
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void RadDataLayout1_ItemInitializing(object sender, Telerik.WinControls.UI.DataLayoutItemInitializingEventArgs e)
{
e.Item.TextAlignment = ContentAlignment.MiddleCenter;
e.Item.TextPosition = Telerik.WinControls.UI.LayoutItemTextPosition.Top;
}
private void Form1_Load(object sender, EventArgs e)
{
radDataLayout1.DataSource = new TestEntity();
}
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.radDataLayout1 = new Telerik.WinControls.UI.RadDataLayout();
((System.ComponentModel.ISupportInitialize)(this.radDataLayout1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.radDataLayout1.LayoutControl)).BeginInit();
this.radDataLayout1.SuspendLayout();
this.SuspendLayout();
//
// radDataLayout1
//
//
// radDataLayout1.LayoutControl
//
this.radDataLayout1.LayoutControl.Dock = System.Windows.Forms.DockStyle.Fill;
this.radDataLayout1.LayoutControl.DrawBorder = false;
this.radDataLayout1.LayoutControl.Location = new System.Drawing.Point(0, 0);
this.radDataLayout1.LayoutControl.Name = "LayoutControl";
this.radDataLayout1.LayoutControl.Size = new System.Drawing.Size(678, 384);
this.radDataLayout1.LayoutControl.TabIndex = 0;
this.radDataLayout1.Location = new System.Drawing.Point(26, 22);
this.radDataLayout1.Name = "radDataLayout1";
this.radDataLayout1.Size = new System.Drawing.Size(680, 386);
this.radDataLayout1.TabIndex = 0;
this.radDataLayout1.ItemInitializing += new Telerik.WinControls.UI.DataLayoutItemInitializingEventHandler(this.RadDataLayout1_ItemInitializing);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.radDataLayout1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.radDataLayout1.LayoutControl)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.radDataLayout1)).EndInit();
this.radDataLayout1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private Telerik.WinControls.UI.RadDataLayout radDataLayout1;
}
public class TestEntity // : TestA, TestB
{
[DisplayName("TestA")]
public string Name { get; set; } = "stuff";
[DisplayName("TestA B")]
public string NameA { get; set; } = "stuff";
[DisplayName("TestA C")]
public string NameB { get; set; } = "stuff";
}
}
Thanks for the code, I was able to reproduce the issue. I can see that you have logged this on our public Feedback Portal. To workaround it you can set the following properties as well:
private
void
RadDataLayout1_ItemInitializing1(
object
sender, DataLayoutItemInitializingEventArgs e)
{
e.Item.ControlVerticalAlignment = RadVerticalAlignment.Bottom;
e.Item.TextPosition = Telerik.WinControls.UI.LayoutItemTextPosition.Top;
e.Item.TextAlignment = ContentAlignment.TopCenter;
e.Item.MaxSize =
new
Size(0, 40); // so the last item does not fill the remaining space
}
Please let me know if there is something else I can help you with.
Regards,
Dimitar
Progress Telerik