I am trying to add layoutcontrolitems but i cant fix their location problem. I add textbox to each layoutcontrolitem and set a layoutcontrolitem.text option. But layoutcontrolitem.text collapse on eachother and also i could not allign the corresponding textbox and label horizontally. There is a screenshot attached to this post.
i am generating this layoutcontrolitems on runtime with a class. Class is below
namespace LayoutControl
{
public class LayoutControl
{
public DevExpress.XtraLayout.LayoutControlItem newlayoutControlItem;
public DevExpress.XtraEditors.TextEdit newtextBox;
public DevExpress.XtraEditors.LabelControl newLabel;
private List<BaseLayoutItem> _LayoutItems = new List<BaseLayoutItem>();
public List<BaseLayoutItem> LayoutItems
{
get
{
return _LayoutItems;
}
set
{
_LayoutItems = value;
}
}
public void InitializeLayoutControl(int fieldCount,
DataColumnCollection textBoxName,
Array fieldValue)
{
LayoutItems.Clear();
int x = 50;
for (int i = 0; i < fieldCount; i++)
{
newlayoutControlItem = new DevExpress.XtraLayout.LayoutControlItem();
newtextBox = new DevExpress.XtraEditors.TextEdit();
((System.ComponentModel.ISupportInitialize)(newlayoutControlItem)).BeginInit();
((System.ComponentModel.ISupportInitialize)(newtextBox.Properties)).BeginInit();
//
// TextEdit ( TextBox)
//
newtextBox.Text = Convert.ToString(fieldValue.GetValue(i));
newtextBox.Location = new System.Drawing.Point(50, x);
newtextBox.Size = new System.Drawing.Size(60, 20);
newtextBox.AutoSizeInLayoutControl = true;
//
// LayoutControlItem
//
newlayoutControlItem.Control = newtextBox;
newlayoutControlItem.Location = new System.Drawing.Point(50, x);
newlayoutControlItem.Size = new System.Drawing.Size(100, 50);
newlayoutControlItem.Text = Convert.ToString(fieldValue.GetValue(i))+":";
newlayoutControlItem.TextLocation = DevExpress.Utils.Locations.Left;
newlayoutControlItem.TextSize = new System.Drawing.Size(50, 20);
newlayoutControlItem.AppearanceItemCaption.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Near;
LayoutItems.Add(newlayoutControlItem);
x = x + 32;
}
((System.ComponentModel.ISupportInitialize)(newtextBox.Properties)).EndInit();
((System.ComponentModel.ISupportInitialize)(newlayoutControlItem)).EndInit();
}
}
}
And this is how i implement this class in my main form //
// layoutControl2
//
this.layoutControl2.Dock = System.Windows.Forms.DockStyle.Left;
this.layoutControl2.Location = new System.Drawing.Point(0, 51);
this.layoutControl2.Name = "layoutControl2";
this.layoutControl2.Root = this.layoutControlGroup2;
this.layoutControl2.Size = new System.Drawing.Size(395, 499);
this.layoutControl2.TabIndex = 5;
this.layoutControl2.Text = "layoutControl2";
//
// layoutControlGroup2
//
this.layoutControlGroup2.CustomizationFormText = "layoutControlGroup2";
this.layoutControlGroup2.Location = new System.Drawing.Point(0, 0);
this.layoutControlGroup2.Name = "layoutControlGroup2";
this.layoutControlGroup2.Size = new System.Drawing.Size(395, 499);
this.layoutControlGroup2.Spacing = new DevExpress.XtraLayout.Utils.Padding(0, 0, 0, 0);
this.layoutControlGroup2.Text = "layoutControlGroup2";
this.layoutControlGroup2.DefaultLayoutType = DevExpress.XtraLayout.Utils.LayoutType.Horizontal;
this.layoutControlGroup2.TextVisible = false;
and inside an event
this.layoutControlGroup2.Clear();
this.layoutControlGroup2.AddRange(testlc.LayoutItems.ToArray());