protected void ChangeCapacity()
{
if (this.RpgType == null || this.DataObjectList == null)
return;
var current = this.Data.Count - 1;
var max = current;
using (var dialog = new ChangeMaxDialog(current, 1, 9999))
{
if (dialog.ShowDialog() == DialogResult.OK)
max = dialog.MaxValue;
}
if (current == max)
return;
var listBoxGeneration = GC.GetGeneration(this.DataObjectList);
var listGeneration = GC.GetGeneration(this.Data);
var index = this.DataObjectList.SelectedIndex;
if (current > max)
this.Data.RemoveRange(max + 1, current - max);
else if (current < max)
{
for (int i = current; i < max; i++)
{
dynamic obj = Activator.CreateInstance(this.RpgType);
obj.id = i + 1;
this.Data.Add(obj);
}
}
this.DataObjectList.PopulateList(this.Data);
this.DataObjectList.SelectedIndex = index.Clamp(0, this.DataObjectList.Items.Count - 1);
GC.Collect(listGeneration, GCCollectionMode.Forced);
GC.Collect(listBoxGeneration, GCCollectionMode.Forced);
}