Adding an empty item to an IList collection at runtime.
if (dataSource.GetType() == typeof(BindingSource))
{
IEnumerator en = dataSource.GetEnumerator();
en.MoveNext();
Type t = en.Current.GetType();
object o = System.Activator.CreateInstance(t, false);
dataSource.Add(o);
}
where dataSource is of type IList.
This was a request to add an empty line to a windows forms combobox and to a listbox.
BindingSource can be bound to any of the following:
- Object
- System.Type
- IEnumerable
- ICollection
- IList
- IListSource
- IBindingList
- IBindingListView
Labels: C#
0 Comments:
Post a Comment
<< Home