in
Forums
Blogs
Files
Devexpress.Com
Client Center
Support Center
DevExpress Channel

programatically adding layoutcontrolitem

Last post 11/6/2008 11:54 AM by Yucel Turkkan. 2 replies.
Page 1 of 1 (3 items)
Sort Posts:
Previous Next
  • 11/4/2008 7:24 AM

    programatically adding layoutcontrolitem

     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());

  • 11/6/2008 11:08 AM In reply to

    • Pavel
    • Top 200 Contributor
    • Joined on 7/4/2007
    • Posts 55

    Re: programatically adding layoutcontrolitem

    try to wrap this code into layoutControlGroup2.BeginUpdate/layoutControlGroup2.EndUpdate Block

    this.layoutControlGroup2.Clear();
    this.layoutControlGroup2.AddRange(testlc.LayoutItems.ToArray());

    WPF HATER BLOG
    http://wpfhater.blogspot.com/
  • 11/6/2008 11:54 AM In reply to

    Re: programatically adding layoutcontrolitem

    yesterday i end up with your solution but this time i faced with some other layout problems so i had to completely change my way of doing this task.

    I inspired from this solution: http://www.devexpress.com/Support/Center/p/Q181061.aspx?searchtext=layoutcontrolitem&tid=4b2d6f97-c4ae-48fc-87f6-8c5da6541e40&pid=-1

    My aim was to create texboxes ,which will show the focused row elements from a datagrid. anyway it seems i did it but i dont know if i am doing it in the right way.

     

    Below are my working codes. But it again does not seem rational. Because every time i focus a new row this code regenerates new set of texboxes etc and it does not seem so logical to create all these again every time.

     

    namespace LayoutControl
    {

        public class RecordDetailsPane : UserControl
        {
            public DevExpress.XtraLayout.LayoutControl newlayoutControl;
            public DevExpress.XtraLayout.LayoutControlGroup detailsPaneLayoutGroup;
            public DevExpress.XtraLayout.LayoutControlGroup buttonPanelGroup;
            public DevExpress.XtraLayout.LayoutControlItem layoutControlItem;
            private int fieldCount;
            private Array labelName;
            private Array fieldValue;

            public void InitializeControl(int _fieldCount,Array _labelName,Array _fieldValue)
              {
                  fieldCount = _fieldCount;
                  labelName = _labelName;
                  fieldValue = _fieldValue;
                  InitializeLayout();
                  RebuildUI();
              }

        
              private void InitializeLayout()
              {
                  newlayoutControl = new DevExpress.XtraLayout.LayoutControl();
                  detailsPaneLayoutGroup = new LayoutControlGroup();
                  buttonPanelGroup = new LayoutControlGroup();
                  ((System.ComponentModel.ISupportInitialize)(newlayoutControl)).BeginInit();
                  ((System.ComponentModel.ISupportInitialize)(detailsPaneLayoutGroup)).BeginInit();
                  ((System.ComponentModel.ISupportInitialize)(buttonPanelGroup)).BeginInit();
                  //
                  // Layout Control
                  //
                  newlayoutControl.Dock = System.Windows.Forms.DockStyle.Fill;
                  newlayoutControl.Location = new System.Drawing.Point(0, 0);
                  newlayoutControl.Name = "Detail Container";
                  newlayoutControl.Root.AddRange(new BaseLayoutItem[ {detailsPaneLayoutGroup,buttonPanelGroup});
                  newlayoutControl.Text = "Detail Container";
                  //
                  // Details Pane Control Group
                  //
                  detailsPaneLayoutGroup.CustomizationFormText = "RecordDetailsGroup";
                  detailsPaneLayoutGroup.Location = new System.Drawing.Point(0, 0);
                  detailsPaneLayoutGroup.Name = "RecordDetailsGroup";
                  detailsPaneLayoutGroup.Text = "Kayıt Detayları";
                  detailsPaneLayoutGroup.ExpandOnDoubleClick = true;
                  detailsPaneLayoutGroup.GroupBordersVisible = true;
                  detailsPaneLayoutGroup.TextLocation = Locations.Top;
                  //
                  // Buttons Pane Control Group
                  //
                  buttonPanelGroup.CustomizationFormText = "ButtonsGroup";
                  buttonPanelGroup.Location = new System.Drawing.Point(0, 0);
                  buttonPanelGroup.Name = "ButtonsGroup";
                  buttonPanelGroup.Text = "Butonlar";
                  buttonPanelGroup.ExpandOnDoubleClick = true;
                  buttonPanelGroup.GroupBordersVisible = true;
                  buttonPanelGroup.TextLocation = Locations.Bottom;
                  //
                  //User Control
                  //
                  Controls.Clear();
                  Controls.Add(newlayoutControl);
                  Name = "DetailsPane";

                  ((System.ComponentModel.ISupportInitialize)(newlayoutControl)).EndInit();
                  ((System.ComponentModel.ISupportInitialize)(detailsPaneLayoutGroup)).EndInit();
                  ((System.ComponentModel.ISupportInitialize)(buttonPanelGroup)).EndInit();
              }

              private void RebuildUI()
              {
                  newlayoutControl.BeginUpdate();
                  newlayoutControl.Controls.Clear();
                  detailsPaneLayoutGroup.Items.Clear();
                  addPropertyGroup();
                  addButtonGroup();
                  newlayoutControl.EndUpdate();
              }

              private void addButtonGroup()
              {
                  LayoutControlGroup buttonGroup = buttonPanelGroup.AddGroup();
                  buttonGroup.DefaultLayoutType = LayoutType.Vertical;
                  buttonGroup.GroupBordersVisible = true;

                  string[ buttonName = { "Kaydet", "İptal", "Sil" };

                  for (int i = 0; i < 3; i++)
                  {
                      DevExpress.XtraEditors.SimpleButton button = new SimpleButton();
                      button.Name = Guid.NewGuid().ToString();
                      button.Text = buttonNameIdea;
                      button.MinimumSize = new System.Drawing.Size(100, 25);
                      button.MaximumSize = new System.Drawing.Size(150, 25);
                      createButtonLayoutItem(buttonGroup, button); 
                  }
                 
              }

              private void addPropertyGroup()
              {
                  LayoutControlGroup group = detailsPaneLayoutGroup.AddGroup();
                  group.DefaultLayoutType = LayoutType.Vertical;
                  group.GroupBordersVisible = false;


                  for (int i = 0; i < fieldCount ; i++)
                  {
                      TextEdit texBox = new TextEdit();
                      texBox.Name = Guid.NewGuid().ToString();
                      texBox.Text = Convert.ToString(fieldValue.GetValue(i));

                      string label = Convert.ToString(labelName.GetValue(i));

                      createLayoutItemWithLabel(group, texBox, label);
                  }
              }


              private void createButtonLayoutItem(LayoutGroup group, Control button)
              {
                  LayoutControlItem buttonLayoutControlItem = new LayoutControlItem();
                  group.Add(buttonLayoutControlItem);
                  buttonLayoutControlItem.Control = button;
                  buttonLayoutControlItem.TextVisible = false;
              }

              private void createLayoutItemWithLabel(LayoutGroup group, Control control, string label)
              {
                  Size itemSize = new Size(250, 30);
                  LayoutControlItem texteditLayoutControItem = new LayoutControlItem();
                  group.Add(texteditLayoutControItem);
                  texteditLayoutControItem.Control = control;
                  texteditLayoutControItem.Text = label;
                  texteditLayoutControItem.AppearanceItemCaption.TextOptions.HAlignment = HorzAlignment.Far;
              }


       
        }
    }

Page 1 of 1 (3 items)
Copyright © 1998-2008 Developer Express Inc.
ALL RIGHTS RESERVED