Click here to Skip to main content
16,018,797 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all,
I was creating a control that has a Interface ("IMyInterface") and a ItemsSource of type IEnumerable. on run time the ItemsSource will be assigned with the Collection (ObservableCollection, List or any other collection type) with class type as below

class with my IMyInterface Implemented

C#
public class ClassName: IMyInterface


My IMyInterface
C#
public interface IMyInterface: ICloneable, INotifyPropertyChanged
   {
       string FirstName{ get; set; }
       string LastName { get; set; }
       bool IsSelected { get; set; }
       bool IsDefault { get; set; }
   }


Collection
C#
public class ClassNameCollection: ObservableCollection<ClassName>


so that i can type cast the collection to my interface type and do some manipulcation like Add/Sort or Remove etc., but i am using Xceed DataGrid i am binding my ItemsSource property to DataGrid using DataGridCollectionViewSource. and i have triggered the following events

C#
private void OndataGridCollectionViewCreatingNewItem(object sender, DataGridCreatingNewItemEventArgs e)
        {
            e.NewItem = duplicateItem;
            e.Handled = true;
        }

        private void OndataGridCollectionViewCommittingNewItem(object sender, DataGridCommittingNewItemEventArgs e)
        {
            List<IMyInterface> source = e.CollectionView.SourceCollection as List<IMyInterface>;
            if (source == null) return;

            //source.Add(e.Item as IManageView);
            e.Index = source.Count() - 1;
            e.NewCount = source.Count();
            e.Handled = true;
        }


in OndataGridCollectionViewCommittingNewItem Event i am trying to type case the ItemSource to List<imyinterface> but Actualy it was failing (the e.CollectionView.SourceCollection is a IEnumerable type, As give in the example by Xceed[^] they are type casting it since List Implements IEnumerable Interface. in the example they are using the direct Collection. but in my case am using a collection of type IMyInterface).

My binding ItemsSource peoperty to DataGrid was below

C#
DataGridCollectionViewSource dataGridCollectionView = new DataGridCollectionViewSource();
            dataGridCollectionView.CreatingNewItem += OndataGridCollectionViewCreatingNewItem;
            dataGridCollectionView.CommittingNewItem += OndataGridCollectionViewCommittingNewItem;
            dataGridCollectionView.Source = itemSource;
            var bind = new Binding { Source = dataGridCollectionView };
            MyViewsManagerDataGrid.SetBinding(ItemsControl.ItemsSourceProperty, bind);


i have got help from the xceed forum Xceed[^] the example give was not working when i implement it. please provide me with a solution.
Posted
Updated 7-Jul-14 6:46am
v6
Comments
Richard MacCutchan 7-Jul-14 9:18am    
but Actualy it was failing.
but i was not working.

Please do not assume that people can guess what either of those statements mean. Edit your question and add the full details of what happens when you try these actions, including the full text of any error messages.
Gold$Coin 7-Jul-14 12:47pm    
ya got it i have updated my question as you suggested. hope it was clear now please let me know if it was even worst.
[no name] 7-Jul-14 14:01pm    
seems alright where is the problem
Gold$Coin 8-Jul-14 0:00am    
in OndataGridCollectionViewCommittingNewItem Event when i try to type cast the sourcecollection to List<imyinterface> as below, because the SourceCollection is of type IEnumerable.

List < imyinterface > source = e.CollectionView.SourceCollection as List < imyinterface >;

but the same example was there in XCEED site.

You should talk to the people who created it - Xceed - they should provide technical support and will know more about their product than we will. If they don't, then find another supplier and demand your money back!

If they wrote the code, they will understand it better that we would - so I'd start there, not here. Unless of course, you haven't paid for it - in which case they probably won't talk to you, and neither would we...
 
Share this answer
 
Comments
Gold$Coin 8-Jul-14 0:04am    
ya will do it and thanks.
changed the binding type and implemented the other way arround.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900