示例#1
0
        /// <summary>
        /// Handles the UnGroup event
        /// </summary>
        /// <param name="sender">Source of the event.</param>
        /// <param name="e">A EventArgs that contains the event data.</param>
        private void OnUngroup(object sender, EventArgs e)
        {
            OutlookGridGroupBoxColumn col = columnsList[indexselected];

            OnColumnGroupRemoved(new OutlookGridColumnEventArgs(new OutlookGridColumn(col.ColumnName, null, null, SortOrder.None, -1, -1)));
            columnsList.Remove(col);
            this.Invalidate();
        }
示例#2
0
        /// <summary>
        /// Handles the SortDescending event
        /// </summary>
        /// <param name="sender">Source of the event.</param>
        /// <param name="e">A EventArgs that contains the event data.</param>
        private void OnSortDescending(object sender, EventArgs e)
        {
            //Change the sortOrder in the list
            OutlookGridGroupBoxColumn col = columnsList[indexselected];

            col.SortDirection = SortOrder.Descending;
            //Raise event
            OnColumnSortChanged(new OutlookGridColumnEventArgs(new OutlookGridColumn(col.ColumnName, null, null, SortOrder.Descending, -1, -1)));
            //Redraw
            this.Invalidate();
        }
示例#3
0
        /// <summary>
        /// Handles the DragDrop event. Add a new grouping column following a drag drop from the grid
        /// </summary>
        /// <param name="sender">Source of the event.</param>
        /// <param name="e">A DragEventArgs that contains the event data.</param>
        private void KryptonOutlookGridGroupBox_DragDrop(object sender, DragEventArgs e)
        {
            string    columnToMove = e.Data.GetData(typeof(string)) as string;
            string    columnName;
            string    columnText;
            SortOrder sortOrder;
            DataGridViewColumnSortMode sortMode;

            string[] res = columnToMove.Split('|');
            columnName = res[0];
            columnText = res[1];
            sortOrder  = (SortOrder)Enum.Parse(typeof(SortOrder), res[2]);//SortOrder.Ascending;
            if (sortOrder == SortOrder.None)
            {
                sortOrder = SortOrder.Ascending;
            }
            sortMode = (DataGridViewColumnSortMode)Enum.Parse(typeof(DataGridViewColumnSortMode), res[3]);
            OutlookGridGroupBoxColumn colToAdd = new OutlookGridGroupBoxColumn(columnName, columnText, sortOrder, res[4]);

            //if (res[4] == typeof(OutlookGridDateTimeGroup).Name)
            colToAdd.GroupInterval      = res[5];
            colToAdd.SortBySummaryCount = CommonHelper.StringToBool(res[6]);
            if (!String.IsNullOrEmpty(columnToMove) && !columnsList.Contains(colToAdd) && sortMode != DataGridViewColumnSortMode.NotSortable)
            {
                //Determine the position of the new Group amongst the others
                int i = 0; //first group order is 0
                //We are sure that we are going to browse the columns from left to right
                foreach (OutlookGridGroupBoxColumn existingColumn in this.columnsList)
                {
                    if (e.X > (existingColumn.Rect.X + existingColumn.Rect.Width / 2))
                    {
                        i++;
                    }
                }
                columnsList.Insert(i, colToAdd);

                //try
                //{
                //Warns the grid of a new grouping
                OnColumnGroupAdded(new OutlookGridColumnEventArgs(new OutlookGridColumn(columnName, null, null, sortOrder, i, -1)));
                this.Invalidate();
                //}
                //catch (Exception exc)
                //{
                //    MessageBox.Show("Failed to group.\n\n Error:" + exc.Message,
                //                      "Grid GroupBox",
                //                      MessageBoxButtons.OK,
                //                      MessageBoxIcon.Error);
                //}
            }
        }
示例#4
0
        /// <summary>
        /// Handles the OnSortBySummaryCount event
        /// </summary>
        /// <param name="sender">Source of the event.</param>
        /// <param name="e">A EventArgs that contains the event data.</param>
        private void OnSortBySummaryCount(object sender, EventArgs e)
        {
            KryptonContextMenuItem    item     = (KryptonContextMenuItem)sender;
            OutlookGridGroupBoxColumn col      = columnsList[indexselected];
            OutlookGridColumn         colEvent = new OutlookGridColumn(col.ColumnName, null, null, SortOrder.None, -1, -1);

            colEvent.GroupingType = new OutlookGridDefaultGroup(null)
            {
                SortBySummaryCount = item.Checked
            };
            col.SortBySummaryCount = item.Checked;
            //Raise event
            OnSortBySummaryCount(new OutlookGridColumnEventArgs(colEvent));
        }
示例#5
0
        /// <summary>
        /// Handles the GroupIntervalClick event
        /// </summary>
        /// <param name="sender">Source of the event.</param>
        /// <param name="e">A EventArgs that contains the event data.</param>
        private void OnGroupIntervalClick(object sender, EventArgs e)
        {
            KryptonContextMenuItem    item     = (KryptonContextMenuItem)sender;
            OutlookGridGroupBoxColumn col      = columnsList[indexselected];
            OutlookGridColumn         colEvent = new OutlookGridColumn(col.ColumnName, null, null, SortOrder.None, -1, -1);

            colEvent.GroupingType = new OutlookGridDateTimeGroup(null)
            {
                Interval = ((OutlookGridDateTimeGroup.DateInterval)Enum.Parse(typeof(OutlookGridDateTimeGroup.DateInterval), item.Tag.ToString()))
            };
            col.GroupInterval = ((OutlookGridDateTimeGroup)colEvent.GroupingType).Interval.ToString();
            //Raise event
            OnGroupIntervalClick(new OutlookGridColumnEventArgs(colEvent));
        }
示例#6
0
        /// <summary>
        /// DO NOT USE THIS FUNCTION YOURSELF, USE the corresponding function in OutlookGrid
        /// Update the grouping columns.
        /// </summary>
        /// <param name="list">The list of OutlookGridColumn</param>
        public void UpdateGroupingColumns(List <OutlookGridColumn> list)
        {
            columnsList.Clear();
            OutlookGridGroupBoxColumn colToAdd;

            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].IsGrouped)
                {
                    colToAdd = new OutlookGridGroupBoxColumn(list[i].DataGridViewColumn.Name, list[i].DataGridViewColumn.HeaderText, list[i].SortDirection, list[i].GroupingType.GetType().Name);
                    if (colToAdd.GroupingType == typeof(OutlookGridDateTimeGroup).Name)
                    {
                        colToAdd.GroupInterval = ((OutlookGridDateTimeGroup)list[i].GroupingType).Interval.ToString();
                    }
                    columnsList.Add(colToAdd);
                }
            }
            this.Invalidate();
        }
示例#7
0
        /// <summary>
        /// Show the context menu for column box
        /// </summary>
        private void ShowColumnBoxContextMenu()
        {
            if (_menuItems == null)
            {
                // Create individual items
                _menuSortAscending              = new KryptonContextMenuItem(LangManager.Instance.GetString("SORTASCENDING"), Properties.Resources.sort_ascending, new EventHandler(OnSortAscending));
                _menuSortDescending             = new KryptonContextMenuItem(LangManager.Instance.GetString("SORTDESCENDING"), Properties.Resources.sort_descending, new EventHandler(OnSortDescending));
                _menuSeparator1                 = new KryptonContextMenuSeparator();
                _menuExpand                     = new KryptonContextMenuItem(LangManager.Instance.GetString("EXPAND"), Properties.Resources.element_plus_16, new EventHandler(OnGroupExpand));
                _menuCollapse                   = new KryptonContextMenuItem(LangManager.Instance.GetString("COLLAPSE"), Properties.Resources.element_minus_16, new EventHandler(OnGroupCollapse));
                _menuUnGroup                    = new KryptonContextMenuItem(LangManager.Instance.GetString("UNGROUP"), Properties.Resources.element_delete, new EventHandler(OnUngroup));
                _menuSeparator2                 = new KryptonContextMenuSeparator();
                _menuFullExpand                 = new KryptonContextMenuItem(LangManager.Instance.GetString("FULLEXPAND"), Properties.Resources.elements_plus_16, new EventHandler(OnFullExpand));
                _menuFullCollapse               = new KryptonContextMenuItem(LangManager.Instance.GetString("FULLCOLLAPSE"), Properties.Resources.elements_minus_16, new EventHandler(OnFullCollapse));
                _menuSeparator3                 = new KryptonContextMenuSeparator();
                _menuClearGrouping              = new KryptonContextMenuItem(LangManager.Instance.GetString("CLEARGROUPING"), Properties.Resources.element_selection_delete, new EventHandler(OnClearGrouping));
                _menuHideGroupBox               = new KryptonContextMenuItem(LangManager.Instance.GetString("HIDEGROUPBOX"), null, new EventHandler(OnHideGroupBox));
                _menuGroupInterval              = new KryptonContextMenuItem(LangManager.Instance.GetString("GROUPINTERVAL"));
                _menuSortBySummary              = new KryptonContextMenuItem(LangManager.Instance.GetString("SORTBYSUMMARYCOUNT"), null, new EventHandler(OnSortBySummaryCount));
                _menuSortBySummary.CheckOnClick = true;

                //Group Interval
                KryptonContextMenuItems _GroupIntervalItems;
                KryptonContextMenuItem  it = null;
                string[] names             = Enum.GetNames(typeof(OutlookGridDateTimeGroup.DateInterval));
                KryptonContextMenuItemBase[] arrayOptions = new KryptonContextMenuItemBase[names.Length];
                for (int i = 0; i < names.Length; i++)
                {
                    it              = new KryptonContextMenuItem(LangManager.Instance.GetString(names[i]));
                    it.Tag          = names[i];
                    it.Click       += OnGroupIntervalClick;
                    arrayOptions[i] = it;
                }
                _GroupIntervalItems = new KryptonContextMenuItems(arrayOptions);
                _menuGroupInterval.Items.Add(_GroupIntervalItems);

                // Add items inside an items collection (apart from separator1 which is only added if required)
                _menuItems = new KryptonContextMenuItems(new KryptonContextMenuItemBase[] { _menuSortAscending,
                                                                                            _menuSortDescending,
                                                                                            _menuSortBySummary,
                                                                                            _menuSeparator1,
                                                                                            _menuGroupInterval,
                                                                                            _menuExpand,
                                                                                            _menuCollapse,
                                                                                            _menuUnGroup,
                                                                                            _menuSeparator2,
                                                                                            _menuFullExpand,
                                                                                            _menuFullCollapse,
                                                                                            _menuSeparator3,
                                                                                            _menuClearGrouping,
                                                                                            _menuHideGroupBox });
            }

            // Ensure we have a krypton context menu if not already present
            if (this.KCtxMenu == null)
            {
                KCtxMenu = new KryptonContextMenu();
            }


            // Update the individual menu options
            OutlookGridGroupBoxColumn col = null;

            if (indexselected > -1)
            {
                col = columnsList[indexselected];
            }

            _menuSortAscending.Visible  = col != null;
            _menuSortDescending.Visible = col != null;
            _menuSortAscending.Checked  = col != null && col.SortDirection == SortOrder.Ascending;
            _menuSortDescending.Checked = col != null && col.SortDirection == SortOrder.Descending;
            _menuSortBySummary.Visible  = col != null;
            _menuSortBySummary.Checked  = col != null && col.SortBySummaryCount;
            _menuExpand.Visible         = col != null;
            _menuCollapse.Visible       = col != null;
            _menuGroupInterval.Visible  = col != null && col.GroupingType == typeof(OutlookGridDateTimeGroup).Name;
            if (_menuGroupInterval.Visible)
            {
                foreach (KryptonContextMenuItem item in ((KryptonContextMenuItems)_menuGroupInterval.Items[0]).Items)
                {
                    item.Checked = item.Tag.ToString() == col.GroupInterval;
                }
            }
            _menuUnGroup.Visible       = col != null;
            _menuFullExpand.Enabled    = columnsList.Count > 0;
            _menuFullCollapse.Enabled  = columnsList.Count > 0;
            _menuClearGrouping.Enabled = columnsList.Count > 0;

            _menuSeparator1.Visible = (_menuSortAscending.Visible || _menuSortDescending.Visible);
            _menuSeparator2.Visible = (_menuExpand.Visible || _menuCollapse.Visible || _menuUnGroup.Visible);
            _menuSeparator3.Visible = (_menuFullExpand.Visible || _menuFullCollapse.Visible);

            if (!KCtxMenu.Items.Contains(_menuItems))
            {
                KCtxMenu.Items.Add(_menuItems);
            }

            // Show the menu!
            KCtxMenu.Show(this);
        }
示例#8
0
        /// <summary>
        /// Overrides the MouseUp event.
        /// </summary>
        /// <param name="e">A MouseEventArgs that contains the event data.</param>
        protected override void OnMouseUp(MouseEventArgs e)
        {
            List <OutlookGridGroupBoxColumn> l = new List <OutlookGridGroupBoxColumn>();
            OutlookGridGroupBoxColumn        columnMovingInsideGroupBox = null;

            foreach (OutlookGridGroupBoxColumn c in this.columnsList)
            {
                if (c.Rect != null)
                {
                    if (c.IsMoving && !this.Bounds.Contains(e.Location))
                    {
                        l.Add(c);
                    }
                    //We move an existing colum inside the groupbox
                    else if (c.IsMoving && this.Bounds.Contains(e.Location))
                    {
                        columnMovingInsideGroupBox = c;
                    }

                    //Stop moving and pressing
                    c.Pressed  = false;
                    c.IsMoving = false;
                }
            }

            //no more dragging
            isDragging = false;

            //Ungroup columns dragged outside the box
            if (l.Count > 0)
            {
                foreach (OutlookGridGroupBoxColumn c in l)
                {
                    //Warn the Grid
                    OnColumnGroupRemoved(new OutlookGridColumnEventArgs(new OutlookGridColumn(c.ColumnName, null, null, SortOrder.None, -1, -1)));

                    columnsList.Remove(c);
                }
            }


            if (columnMovingInsideGroupBox != null)
            {
                if (e.Location.X != columnMovingInsideGroupBox.Rect.X && (e.Location.X < columnMovingInsideGroupBox.Rect.X || e.Location.X > (columnMovingInsideGroupBox.Rect.X + columnMovingInsideGroupBox.Rect.Width)))
                {
                    int i = 0; //first group order is 0

                    foreach (OutlookGridGroupBoxColumn existingColumns in this.columnsList)
                    {
                        if (e.Location.X > (existingColumns.Rect.X + existingColumns.Rect.Width / 2) && existingColumns != columnMovingInsideGroupBox)
                        {
                            i++;
                        }
                    }
                    OnColumnGroupOrderChanged(new OutlookGridColumnEventArgs(new OutlookGridColumn(columnMovingInsideGroupBox.ColumnName, null, null, SortOrder.None, i, -1)));
                    //MessageBox.Show("Changed order = " + i.ToString());
                }
            }

            this.Invalidate();
            base.OnMouseDown(e);
        }