[TypeConverter (typeof (ObjectContainerConverter))]
private class ObjectContainer
{
- internal string Name;
internal object Object;
internal CollectionEditor editor;
- public ObjectContainer (string name, object obj, CollectionEditor editor)
+ public ObjectContainer (object obj, CollectionEditor editor)
{
- this.Name = name;
this.Object = obj;
this.editor = editor;
}
+ internal string Name {
+ get { return editor.GetDisplayText (Object); }
+ }
+
public override string ToString ()
{
return Name;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.ResumeLayout (false);
-#if NET_2_0
if (editor.CollectionType.IsGenericType)
this.Text = editor.CollectionItemType.Name + " Collection Editor";
else
this.Text = editor.CollectionType.Name + " Collection Editor";
-#else
- this.Text = editor.CollectionType.Name + " Collection Editor";
-#endif
foreach (Type type in editor.NewItemTypes)
addType.Items.Add (type.Name);
if (addType.Items.Count > 0)
itemsList.BeginUpdate ();
itemsList.Items.Clear ();
foreach (object o in items)
- this.itemsList.Items.Add (new ObjectContainer (editor.GetDisplayText (o), o, editor));
+ this.itemsList.Items.Add (new ObjectContainer (o, editor));
if (itemsList.Items.Count > 0)
itemsList.SelectedIndex = 0;
itemsList.EndUpdate ();
for (int i = 0; i < itemsList.SelectedItems.Count; i++)
selected[i] = itemsList.Items.IndexOf (itemsList.SelectedItems[i]);
- SetEditValue (); // ends up calling OnEditValueChanged which repopulates the list
+ // The list might be repopulated if a new instance of the collection edited
+ // is created during the update. This happen for example for Arrays.
+ SetEditValue ();
+ // Restore current selection in case the list gets repopulated.
+ // Refresh the item after that to reflect possible value change.
+ //
itemsList.BeginUpdate ();
itemsList.ClearSelected ();
- foreach (int index in selected)
+ foreach (int index in selected) {
+ itemsList.DoRefreshItem (index);
itemsList.SetSelected (index, true);
+ }
itemsList.SelectedIndex = selected[0];
itemsList.EndUpdate ();
}
DisplayError (ex);
return;
}
- itemsList.Items.Add (new ObjectContainer (editor.GetDisplayText (o), o, editor));
+ itemsList.Items.Add (new ObjectContainer (o, editor));
itemsList.SelectedIndex = -1;
itemsList.SelectedIndex = itemsList.Items.Count - 1;
}
private void doRemove_Click (object sender, EventArgs e)
{
- if (itemsList.SelectedIndex != -1)
- itemsList.Items.RemoveAt (itemsList.SelectedIndex);
- if (itemsList.SelectedItems.Count == 0)
- itemDisplay.SelectedObject = null;
+ if (itemsList.SelectedIndex != -1) {
+ int[] selected = new int[itemsList.SelectedItems.Count];
+ for (int i=0; i < itemsList.SelectedItems.Count; i++)
+ selected[i] = itemsList.Items.IndexOf (itemsList.SelectedItems[i]);
+
+ for (int i = selected.Length - 1; i >= 0; i--)
+ itemsList.Items.RemoveAt (selected[i]);
+
+ itemsList.SelectedIndex = Math.Min (selected[0], itemsList.Items.Count-1);
+ }
}
+ // OnEditValueChanged is called only if the EditValue has changed,
+ // which is only in the case when a new instance of the collection is
+ // required, e.g for arrays.
+ //
protected override void OnEditValueChanged ()
{
UpdateItems ();
}
if (instance == null) {
-#if NET_2_0
instance = TypeDescriptor.CreateInstance (provider, itemType, null, null);
-#else
- instance = Activator.CreateInstance (itemType);
-#endif
}
return instance;
}