Пример #1
0
        /// <summary>
        /// mouse Right-click menu
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            if (e.Button == MouseButtons.Right)
            {
                // 현재 클릭한 GridItem 가져오기
                UIElement element      = this.DisplayLayout.UIElement.ElementFromPoint(new Point(e.X, e.Y));
                object    selectedItem = element.GetContext();

                this.ActiveCell = null;
                this.Selected.Rows.Clear();
                this.Selected.Cells.Clear();
                this.Selected.Columns.Clear();

                if (selectedItem is ColumnHeader)
                {
                    ColumnHeader columnHeader = (ColumnHeader)element.GetContext(typeof(ColumnHeader));
                    columnHeader.Selected = true;
                    foreach (var row in this.Rows)
                    {
                        row.Cells[columnHeader.Column].Activate();
                        this.ActiveCell.Selected = true;
                    }
                }

                if (selectedItem is UltraGridColumn)
                {
                    UltraGridCell activeCell = (UltraGridCell)element.GetContext(typeof(UltraGridCell));
                    activeCell.Activate();
                }

                // 1. 컨텍스트 메뉴 구성(생성)
                ContextMenuStrip strip = this.CreateContextMenu(element);

                // 2. 컨텍스트 메뉴 사용 가능/불가능 처리
                this.AdjustContextMenuItems(strip, element);

                strip.Show(this, new Point(e.X, e.Y));
            }
        }
Пример #2
0
            private void aCheckBoxUIElement_ElementClick(Object sender, Infragistics.Win.UIElementEventArgs e)
            {
                // Get the CheckBoxUIElement that was clicked
                CheckBoxUIElement aCheckBoxUIElement = (CheckBoxUIElement)e.Element;

                // Get the Header associated with this particular element
                Infragistics.Win.UltraWinGrid.ColumnHeader aColumnHeader = (Infragistics.Win.UltraWinGrid.ColumnHeader)aCheckBoxUIElement.GetAncestor(typeof(HeaderUIElement)).GetContext(typeof(Infragistics.Win.UltraWinGrid.ColumnHeader));

                // Set the Tag on the Header to the new CheckState
                aColumnHeader.Tag = aCheckBoxUIElement.CheckState;

                // So that we can apply various changes only to the relevant Rows collection that the header belongs to
                HeaderUIElement aHeaderUIElement = aCheckBoxUIElement.GetAncestor(typeof(HeaderUIElement)) as HeaderUIElement;
                RowsCollection  hRows            = aHeaderUIElement.GetContext(typeof(RowsCollection)) as RowsCollection;

                // Raise an event so the programmer can do something when the CheckState changes
                if (_CLICKED != null)
                {
                    _CLICKED(this, new HeaderCheckBoxEventArgs(aColumnHeader, aCheckBoxUIElement.CheckState, hRows));
                }
            }
Пример #3
0
            public void AfterCreateChildElements(Infragistics.Win.UIElement parent) // Implements Infragistics.Win.IUIElementCreationFilter.AfterCreateChildElements
            {
                // Check for the HeaderUIElement
                if (parent is HeaderUIElement)
                {
                    // Get the HeaderBase object from the HeaderUIElement
                    Infragistics.Win.UltraWinGrid.HeaderBase aHeader = ((HeaderUIElement)parent).Header;

                    // Only put the checkbox into headers whose DataType is boolean
                    if (aHeader.Column.DataType == typeof(bool))
                    {
                        TextUIElement     aTextUIElement;
                        CheckBoxUIElement aCheckBoxUIElement = (CheckBoxUIElement)parent.GetDescendant(typeof(CheckBoxUIElement));

                        // Since the grid sometimes re-uses UIElements, we need to check to make sure
                        // the header does not already have a CheckBoxUIElement attached to it.
                        // If it does, we just get a reference to the existing CheckBoxUIElement,
                        // and reset its properties.
                        if (aCheckBoxUIElement == null)
                        {
                            //Create a New CheckBoxUIElement
                            aCheckBoxUIElement = new CheckBoxUIElement(parent);
                        }

                        // Get the TextUIElement - this is where the text for the
                        // Header is displayed. We need this so we can push it to the right
                        // in order to make room for the CheckBox
                        aTextUIElement = (TextUIElement)parent.GetDescendant(typeof(TextUIElement));

                        // Sanity check
                        if (aTextUIElement == null)
                        {
                            return;
                        }

                        // Get the Header and see if the Tag has been set. If the Tag is
                        // set, we will assume it's the stored CheckState. This has to be
                        // done in order to maintain the CheckState when the grid repaints and
                        // UIElement are destroyed and recreated.
                        Infragistics.Win.UltraWinGrid.ColumnHeader aColumnHeader =
                            (Infragistics.Win.UltraWinGrid.ColumnHeader)aCheckBoxUIElement.GetAncestor(typeof(HeaderUIElement))
                            .GetContext(typeof(Infragistics.Win.UltraWinGrid.ColumnHeader));

                        if (aColumnHeader.Tag == null)
                        {
                            //If the tag was nothing, this is probably the first time this
                            //Header is being displayed, so default to Indeterminate
                            aColumnHeader.Tag = CheckState.Indeterminate;
                        }
                        else
                        {
                            aCheckBoxUIElement.CheckState = (CheckState)aColumnHeader.Tag;
                        }

                        // Hook the ElementClick of the CheckBoxUIElement
                        aCheckBoxUIElement.ElementClick += new UIElementEventHandler(aCheckBoxUIElement_ElementClick);

                        // Add the CheckBoxUIElement to the HeaderUIElement
                        parent.ChildElements.Add(aCheckBoxUIElement);

                        // Position the CheckBoxUIElement. The number 3 here is used for 3
                        // pixels of padding between the CheckBox and the edge of the Header.
                        // The CheckBox is shifted down slightly so it is centered in the header.
                        aCheckBoxUIElement.Rect = new Rectangle(parent.Rect.X + 3, parent.Rect.Y + ((parent.Rect.Height - aCheckBoxUIElement.CheckSize.Height) / 2), aCheckBoxUIElement.CheckSize.Width, aCheckBoxUIElement.CheckSize.Height);

                        // Push the TextUIElement to the right a little to make
                        // room for the CheckBox. 3 pixels of padding are used again.
                        aTextUIElement.Rect = new Rectangle(aCheckBoxUIElement.Rect.Right + 3, aTextUIElement.Rect.Y, parent.Rect.Width - (aCheckBoxUIElement.Rect.Right - parent.Rect.X), aTextUIElement.Rect.Height);
                    }
                    else
                    {
                        // If the column is not a boolean column, we do not want to have a checkbox in it
                        // Since UIElements can be reused by the grid, there is a chance that one of the
                        // HeaderUIElements that we added a checkbox to for a boolean column header
                        // will be reused in a column that is not boolean.  In this case, we must remove
                        // the checkbox so that it will not appear in an inappropriate column header.
                        CheckBoxUIElement aCheckBoxUIElement = (CheckBoxUIElement)parent.GetDescendant(typeof(CheckBoxUIElement));

                        if (aCheckBoxUIElement != null)
                        {
                            parent.ChildElements.Remove(aCheckBoxUIElement);
                            aCheckBoxUIElement.Dispose();
                        }
                    }
                }
            }
Пример #4
0
 public HeaderCheckBoxEventArgs(Infragistics.Win.UltraWinGrid.ColumnHeader hdrColumnHeader, CheckState chkCheckState, RowsCollection Rows)
 {
     mvarColumnHeader   = hdrColumnHeader;
     mvarCheckState     = chkCheckState;
     mvarRowsCollection = Rows;
 }
Пример #5
0
        private ContextMenuStrip CreateContextMenu(UIElement element)
        {
            ContextMenuStrip  strip = new ContextMenuStrip();
            ToolStripMenuItem item  = null;

            ColumnHeader header = (ColumnHeader)element.GetContext(typeof(ColumnHeader));

            // 행 추가
            item              = new ToolStripMenuItem("행 추가", Properties.Resources.new_16);
            item.Name         = "add";
            item.Click       += this.HandleContextMenuMouseClick;
            item.ShortcutKeys = (Keys.Control | Keys.N);
            item.Enabled      = false;
            item.Tag          = header;
            strip.Items.Add(item);

            // 행 삭제
            item              = new ToolStripMenuItem("행 삭제", Properties.Resources.delete_16);
            item.Name         = "delete";
            item.Click       += this.HandleContextMenuMouseClick;
            item.ShortcutKeys = (Keys.Control | Keys.D);
            item.Enabled      = false;
            item.Tag          = header;
            strip.Items.Add(item);

            // 행 편집
            item              = new ToolStripMenuItem("셀 편집", Properties.Resources.edit_16);
            item.Name         = "edit";
            item.Click       += this.HandleContextMenuMouseClick;
            item.ShortcutKeys = (Keys.F2);
            item.Enabled      = false;
            item.Tag          = header;
            strip.Items.Add(item);

            strip.Items.Add(new ToolStripSeparator());

            // 복사
            item              = new ToolStripMenuItem("복사", Properties.Resources.copy_16);
            item.Name         = "copy";
            item.Click       += this.HandleContextMenuMouseClick;
            item.ShortcutKeys = (Keys.Control | Keys.C);
            item.Enabled      = false;
            item.Tag          = header;
            strip.Items.Add(item);

            // 붙여넣기
            item              = new ToolStripMenuItem("붙여넣기", Properties.Resources.paste_16);
            item.Name         = "paste";
            item.Click       += this.HandleContextMenuMouseClick;
            item.ShortcutKeys = (Keys.Control | Keys.V);
            item.Enabled      = false;
            item.Tag          = header;
            strip.Items.Add(item);

            strip.Items.Add(new ToolStripSeparator());

            // 엑셀 내보내기
            item         = new ToolStripMenuItem("Excel로 내보내기", Properties.Resources.excel_16);
            item.Name    = "excel";
            item.Click  += this.HandleContextMenuMouseClick;
            item.Enabled = true;
            item.Tag     = header;
            strip.Items.Add(item);

            // 구분선
            strip.Items.Add(new ToolStripSeparator());

            // 열 필터
            item         = new ToolStripMenuItem("열 필터", Properties.Resources.filter_16);
            item.Name    = "filter";
            item.Click  += HandleContextMenuMouseClick;
            item.Enabled = false;
            item.Tag     = header;
            strip.Items.Add(item);

            // 오름차순
            item         = new ToolStripMenuItem("오름차순", Properties.Resources.asc_16);
            item.Name    = "asc";
            item.Click  += HandleContextMenuMouseClick;
            item.Enabled = false;
            item.Tag     = header;
            strip.Items.Add(item);

            // 내림차순
            item         = new ToolStripMenuItem("내림차순", Properties.Resources.desc_16);
            item.Name    = "desc";
            item.Click  += HandleContextMenuMouseClick;
            item.Enabled = false;
            item.Tag     = header;
            strip.Items.Add(item);

            // 정렬없음
            item         = new ToolStripMenuItem("정렬없음", null);
            item.Name    = "none";
            item.Click  += HandleContextMenuMouseClick;
            item.Enabled = false;
            item.Tag     = header;
            strip.Items.Add(item);

            return(strip);
        }