本文整理汇总了C#中Xceed.Wpf.DataGrid.DataGridControl.OnAddingNewDataItem方法的典型用法代码示例。如果您正苦于以下问题:C# DataGridControl.OnAddingNewDataItem方法的具体用法?C# DataGridControl.OnAddingNewDataItem怎么用?C# DataGridControl.OnAddingNewDataItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Xceed.Wpf.DataGrid.DataGridControl
的用法示例。
在下文中一共展示了DataGridControl.OnAddingNewDataItem方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddNewDataItem
public static object AddNewDataItem(
IEnumerable itemsSourceCollection,
DataGridControl dataGridControl,
out int itemIndex )
{
DataGridCollectionViewBase dataGridCollectionViewBase = itemsSourceCollection as DataGridCollectionViewBase;
if( dataGridCollectionViewBase != null )
{
if( !dataGridCollectionViewBase.CanAddNew )
throw new InvalidOperationException( "An attempt was made to add a new data item to a source that does not support insertion." );
itemIndex = dataGridCollectionViewBase.Count;
return dataGridCollectionViewBase.AddNew();
}
if( ( dataGridControl != null ) && ( dataGridControl.ItemsSource == null ) )
{
//unbound
#pragma warning disable 618
AddingNewDataItemEventArgs eventArgs = new AddingNewDataItemEventArgs();
dataGridControl.OnAddingNewDataItem( eventArgs );
object newItem = eventArgs.DataItem;
#pragma warning restore 618
if( newItem == null )
throw new InvalidOperationException( "The AddingNewDataItem event did not return a new data item because the grid is not bound to a data source." );
itemIndex = dataGridControl.Items.Add( newItem );
return newItem;
}
DataView dataView = itemsSourceCollection as DataView;
if( dataView == null )
{
CollectionView collectionView = itemsSourceCollection as CollectionView;
dataView = ( collectionView == null ) ?
null : collectionView.SourceCollection as DataView;
}
if( dataView != null )
{
itemIndex = dataView.Count;
return dataView.AddNew();
}
IBindingList bindingList = itemsSourceCollection as IBindingList;
if( bindingList == null )
{
CollectionView collectionView = itemsSourceCollection as CollectionView;
bindingList = ( collectionView == null ) ?
null : collectionView.SourceCollection as IBindingList;
}
if( ( bindingList != null ) && ( bindingList.AllowNew ) )
{
itemIndex = bindingList.Count;
return bindingList.AddNew();
}
Type itemType = ItemsSourceHelper.GetItemTypeFromEnumeration( itemsSourceCollection );
if( itemType == null )
throw new InvalidOperationException( "An attempt was made to use a source whose item type cannot be determined." );
try
{
itemIndex = -1;
return Activator.CreateInstance( itemType );
}
catch( MissingMethodException exception )
{
throw new InvalidOperationException( "An attempt was made to use a source whose item type does not have a default constructor.", exception );
}
catch( Exception exception )
{
throw new InvalidOperationException( "An unsuccessful attempt was made to create an instance of the source's item type using the item's default constructor.", exception );
}
}