System.Windows.Forms.TableRow.AddjustItemsCountTo C# (CSharp) Method

AddjustItemsCountTo() private method

private AddjustItemsCountTo ( int n ) : void
n int
return void
        internal void AddjustItemsCountTo(int n)
        {
            if (Items == null)
                Items = new object[n];
            else if (Items.Length != n)
            {
                var newItems = new object[n];
                if (Items.Length > n)
                    Array.Copy(Items, 0, newItems, 0, newItems.Length);
                else
                    Array.Copy(Items, 0, newItems, 0, Items.Length);
                Items = newItems;
            }
        }

Usage Example

Example #1
0
        internal void UpdateRow(TableRow row, bool align = true)
        {
            CreateTopLeftButton();

            if (row.control == null)
            {
                var rButton = new TableRowButton(ColumnsStyle);
                rButton.Size = new Size(40, row.Height);
                rButton.Text = Rows.Count.ToString();

                row.control = rButton;
                Controls.Add(rButton);
            }

            if (row.Items.Length != Columns.Count)
            {
                row.AddjustItemsCountTo(Columns.Count);
            }

            if (row.ItemsControls == null)
            {
                row.ItemsControls = new TableRow.TableRowControlsCollection(row, Columns.Count);
            }
            if (row.ItemsControls.Length != row.Items.Length)
            {
                var newControls = new Control[Columns.Count];
                if (row.ItemsControls.Length > newControls.Length) // Dispose unnecessary controls.
                {
                    Array.Copy(row.ItemsControls.items, 0, newControls, 0, newControls.Length);
                    for (int i = newControls.Length; i < row.ItemsControls.Length; i++)
                    {
                        row.ItemsControls[i].Dispose();
                    }
                }
                else
                {
                    Array.Copy(row.ItemsControls.items, 0, newControls, 0, row.ItemsControls.Length);
                }
                row.ItemsControls.items = newControls;
            }
            for (int i = 0; i < row.Items.Length; i++)
            {
                if (row.ItemsControls[i] != null)
                {
                    continue;
                }

                int     controlColumn = i;
                TextBox itemControl   = new TextBox();
                itemControl.BorderColor  = Color.Transparent;
                itemControl.Size         = new Size(Columns[i].Width, row.Height);
                itemControl.TextChanged += (s, a) =>
                {
                    row.Items[controlColumn] = itemControl.Text;
                };
                if (row.Items[i] != null)
                {
                    itemControl.Text = row.Items[i].ToString();
                }

                row.ItemsControls[i] = itemControl;
            }

            if (align)
            {
                AlignRows();
            }
        }
All Usage Examples Of System.Windows.Forms.TableRow::AddjustItemsCountTo