private void GenericQbItemEditor_Load(object sender, EventArgs e)
{
bool tooManyItems = false;
int spacing = 22;
int top = 20;
int tabIndex = this.TabIndex;
int lblWidth = 0;
List<GenericQbItem> gis = QbFile.GetGenericItems(base.QbItem);
if (gis.Count > 500)
{
tooManyItems = true;
this.AutoScrollMinSize = new Size(0, (top * 2) + (spacing * (1 + 1) + 10)); //+ 1 for button
}
else
this.AutoScrollMinSize = new Size(0, (top * 2) + (spacing * (gis.Count + 1) + 10)); //+ 1 for button
this.Tag = base.QbItem; //store item for update
bool hasEditable = false;
try
{
int qbItemFound = 0;
if (gis.Count > 0 && gis[gis.Count - 1].SourceProperty == "ItemQbKey") //nasty hack
{
addEditItem(spacing, ref top, ref lblWidth, ref hasEditable, gis[gis.Count - 1]);
qbItemFound = 1;
}
if (!tooManyItems)
{
for (int i = 0; i < gis.Count - qbItemFound; i++)
addEditItem(spacing, ref top, ref lblWidth, ref hasEditable, gis[i]);
}
}
catch (Exception ex)
{
base.ShowException("Edit Item List Error", ex);
}
foreach (GenericQbEditItem et in this.Controls)
et.TextBoxLeft = lblWidth + 6;
try
{
if (this.Controls.Count != 0)
{
Button btnUpdateItems = new Button();
btnUpdateItems.Text = "&Update";
btnUpdateItems.Anchor = AnchorStyles.Top | AnchorStyles.Right;
btnUpdateItems.Left = (this.ClientSize.Width - btnUpdateItems.Width - 15);
btnUpdateItems.Top = top + 10;
btnUpdateItems.Height = 22;
btnUpdateItems.Enabled = hasEditable;
btnUpdateItems.Click += new EventHandler(btnUpdateItems_Click);
this.Controls.Add(btnUpdateItems);
}
if (tooManyItems)
base.ShowError("Too Many Items", string.Format("This item contains {0} items. It is likely that it should be edited by a dedicated application.", gis.Count.ToString()));
}
catch (Exception ex)
{
base.ShowException("Update Button Error", ex);
}
}