public Form1()
        {
            InitializeComponent();
            //CitiBankEntities1 data = new CitiBankEntities1();
            //var query = data.Student.ToList();
            //IList<Student> list = query;
            //DataTable dt = new DataTable();
            List <SK> s2 = new List <SK>();

            SK l = new SK();

            l.ID   = 3;
            l.Name = "dsdf";
            s2.Add(l);

            SK k = new SK();

            k.ID   = 4;
            k.Name = "dsf";
            s2.Add(k);
            IList <SK> list             = s2;
            FilteredBindingList <SK> sm = new FilteredBindingList <SK>(list);

            //BindingCollection<Student> s = new BindingCollection<Student>(list);

            BindingSource dataSource = new BindingSource();

            dataSource.DataSource             = sm;
            dataGridView1.DataSource          = dataSource;
            this.dataGridView1.SummaryColumns = new string[] { "ID" };

            //Show the SummaryBox
            this.dataGridView1.SummaryRowVisible = true;
        }
Exemple #2
0
        protected override void ApplySortCore(PropertyDescriptor prop,
                                              ListSortDirection direction)
        {
            sortedList = new ArrayList();

            // Check to see if the property type we are sorting by implements
            // the IComparable interface.
            Type interfaceType = prop.PropertyType.GetInterface("IComparable");

            if (interfaceType != null)
            {
                // If so, set the SortPropertyValue and SortDirectionValue.
                sortPropertyValue  = prop;
                sortDirectionValue = direction;

                unsortedItems = new FilteredBindingList <T>();

                if (sortPropertyValue != null)
                {
                    // Loop through each item, adding it the the sortedItems ArrayList.
                    foreach (Object item in this.Items)
                    {
                        unsortedItems.Add((T)item);
                        sortedList.Add(prop.GetValue(item));
                    }
                }
                // Call Sort on the ArrayList.
                sortedList.Sort();
                T temp;

                // Check the sort direction and then copy the sorted items
                // back into the list.
                if (direction == ListSortDirection.Descending)
                {
                    sortedList.Reverse();
                }

                for (int i = 0; i < this.Count; i++)
                {
                    int position = Find(prop.Name, sortedList[i]);
                    if (position != i && position > 0)
                    {
                        temp           = this[i];
                        this[i]        = this[position];
                        this[position] = temp;
                    }
                }

                isSortedValue = true;

                // If the list does not have a filter applied,
                // raise the ListChanged event so bound controls refresh their
                // values. Pass -1 for the index since this is a Reset.
                if (String.IsNullOrEmpty(Filter))
                {
                    OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1));
                }
            }
            else
            {
                // If the property type does not implement IComparable, let the user
                // know.
                throw new InvalidOperationException("Cannot sort by "
                                                    + prop.Name + ". This" + prop.PropertyType.ToString() +
                                                    " does not implement IComparable");
            }
        }