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