private void CopyCellProperties(DataGridViewColumnHeaderCell oldHeaderCell)
        {
            ContextMenuStrip = oldHeaderCell.ContextMenuStrip;
            ErrorText        = oldHeaderCell.ErrorText;
            Tag         = oldHeaderCell.Tag;
            ToolTipText = oldHeaderCell.ToolTipText;
            Value       = oldHeaderCell.Value;
            ValueType   = oldHeaderCell.ValueType;

            // Use HasStyle to avoid creating a new style object
            // when the Style property has not previously been set.
            if (oldHeaderCell.HasStyle)
            {
                Style = oldHeaderCell.Style;
            }

            // Copy this type's properties if the old cell is an auto-filter cell.
            // This enables the Clone method to reuse this constructor.
            var cell = oldHeaderCell as DataGridViewDropdownColumnHeaderCell;

            if (cell != null)
            {
                m_currentDropDownButtonPaddingOffset = cell.m_currentDropDownButtonPaddingOffset;
            }
        }
Exemplo n.º 2
0
        void HistoryFieldDataGridViewColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            DataGridViewColumn           column = Columns[e.ColumnIndex];
            DataGridViewColumnHeaderCell header = column.HeaderCell;

            if (DataSource is not DataView view)
            {
                return;
            }
            //
            // Apply the default sort for the column data type.
            //
            if (header.SortGlyphDirection == SortOrder.Ascending)
            {
                header.SortGlyphDirection = SortOrder.Descending;
                view.Sort = string.Format("{0} DESC", column.Name);
            }
            else
            {
                header.SortGlyphDirection = SortOrder.Ascending;
                view.Sort = string.Format("{0} ASC", column.Name);
            }

            RefreshEdit();
        }
Exemplo n.º 3
0
        /// <summary>
        ///     ColumnHeaderCell constructor
        /// </summary>
        /// <param name="oldCell"></param>
        /// <param name="filterEnabled"></param>
        public ColumnHeaderCell(DataGridViewColumnHeaderCell oldCell, bool filterEnabled)
        {
            Tag              = oldCell.Tag;
            ErrorText        = oldCell.ErrorText;
            ToolTipText      = oldCell.ToolTipText;
            Value            = oldCell.Value;
            ValueType        = oldCell.ValueType;
            ContextMenuStrip = oldCell.ContextMenuStrip;
            Style            = oldCell.Style;
            _filterEnabled   = filterEnabled;

            var oldCellt = oldCell as ColumnHeaderCell;

            if (oldCellt != null && oldCellt.MenuStrip != null)
            {
                MenuStrip                 = oldCellt.MenuStrip;
                _filterImage              = oldCellt._filterImage;
                _filterButtonPressed      = oldCellt._filterButtonPressed;
                _filterButtonOver         = oldCellt._filterButtonOver;
                _filterButtonOffsetBounds = oldCellt._filterButtonOffsetBounds;
                _filterButtonImageBounds  = oldCellt._filterButtonImageBounds;
                MenuStrip.FilterChanged  += menuStrip_FilterChanged;
                MenuStrip.SortChanged    += menuStrip_SortChanged;
            }
            else
            {
                MenuStrip = new MenuStrip(oldCell.OwningColumn.ValueType);
                MenuStrip.FilterChanged += menuStrip_FilterChanged;
                MenuStrip.SortChanged   += menuStrip_SortChanged;
            }

            IsFilterDateAndTimeEnabled = FilterDateAndTimeDefaultEnabled;
            IsSortEnabled   = true;
            IsFilterEnabled = true;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Handles the Column Header Mouse Click event of the <see cref="DataGridView"/>.
        /// </summary>
        private void DtgLogMessagesColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                cmColumns.Items.Clear();

                foreach (DataGridViewColumn column in dtgLogMessages.Columns)
                {
                    DataGridViewColumnHeaderCell headerCell = column.HeaderCell;

                    if (headerCell != null && headerCell.OwningColumn != null)
                    {
                        if (headerCell.OwningColumn.Index == 0)
                        {
                            continue;
                        }

                        cmColumns.Items.Add(CreateColumnSelectItem(
                                                headerCell.OwningColumn.HeaderText
                                                , headerCell.OwningColumn.Visible
                                                , headerCell));
                    }
                }

                cmColumns.Show(
                    this
                    , PointToClient(Cursor.Position));
            }
        }
Exemplo n.º 5
0
            /// <summary>
            /// Latest
            /// </summary>
            /// <param name="DGV"></param>
            /// <param name="DGVStartFromColumn"></param>
            /// <param name="Comment"></param>
            /// <param name="ParentRelation"></param>
            /// <param name="ParentColumnNameWithTipData"></param>
            public static void ColumnHeaderWithCommonTimeDurationFrom(ref DataGridView DGV, int DGVStartFromColumn, string Comment, string ParentRelation, string ParentColumnNameWithTipData)
            {
                HashSet <int> set = new HashSet <int>();
                IEnumerable <DataGridViewCell> cells = Selected(DGV, true);

                cells = cells.Where(CellsFromCol(DGVStartFromColumn));
                cells = cells.Where(o => set.Add(o.ColumnIndex)).ToList();

                foreach (DataGridViewCell cell in cells)
                {
                    DataRow tag = (DataRow)cell.Tag;

                    DataRow parent = tag.GetParentRow(ParentRelation);
                    if (parent == null)
                    {
                        continue;
                    }
                    if (parent.IsNull(ParentColumnNameWithTipData))
                    {
                        continue;
                    }
                    double   time = Convert.ToDouble(parent[ParentColumnNameWithTipData]);
                    TimeSpan span = TimeSpan.FromSeconds(time);
                    string   str  = Dumb.Dumb.ToReadableString(span);
                    DataGridViewColumnHeaderCell headerCell = cell.OwningColumn.HeaderCell;
                    headerCell.ToolTipText = headerCell.ToolTipText + Comment + str + "\n";
                }
                set.Clear();
                set   = null;
                cells = null;
                DGV.ClearSelection();
            }
        /// <summary></summary>
        /// <param name="oldHeaderCell">The DataGridViewColumnHeaderCell to copy property values from.</param>
        /// <param name="items"></param>
        public DataGridViewDropdownColumnHeaderCell(DataGridViewColumnHeaderCell oldHeaderCell, SortedList <int, string> items)
        {
            CopyCellProperties(oldHeaderCell);

            // add the items to a ContextMenuStrip
            SetupDropdownMenu(items);
        }
        void InsertCheckBoxColumn()
        {
            if (dgvOrders.Columns.Count <= 0)
            {
                return;
            }
            var colCb = new DataGridViewCheckBoxColumn {
                Width = 30, Frozen = true
            };

            _cbHeader = new DatagridViewCheckBoxHeaderCell();
            _cbHeader.OnCheckBoxClicked += cbHeader_OnCheckBoxClicked;
            colCb.HeaderCell             = _cbHeader;
            dgvOrders.Columns.Insert(0, colCb);

            var colCb1 = new DataGridViewCheckBoxColumn {
                Width = 120, Frozen = false
            };
            var _cbHeader1 = new DataGridViewColumnHeaderCell();

            _cbHeader1.Value = "Create Case";
            // _cbHeader.OnCheckBoxClicked += cbHeader_OnCheckBoxClicked;
            colCb1.HeaderCell = _cbHeader1;
            dgvOrders.Columns.Insert(2, colCb1);
        }
Exemplo n.º 8
0
        private void dataGridProject_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            DataGridViewColumn           selcol  = dataGridProject.Columns[e.ColumnIndex];
            DataGridViewColumnHeaderCell hdrCell = selcol.HeaderCell;
            SortOrder order    = hdrCell.SortGlyphDirection;
            SortOrder newOrder = SortOrder.None;

            if (order == SortOrder.None || order == SortOrder.Descending)
            {
                newOrder = SortOrder.Ascending;
            }
            else
            {
                newOrder = SortOrder.Descending;
            }
            dataGridProjectSort(selcol.DataPropertyName, hdrCell.SortGlyphDirection);
            hdrCell.SortGlyphDirection = newOrder;
            foreach (DataGridViewColumn col in dataGridProject.Columns)
            {
                if (col.Index == e.ColumnIndex)
                {
                    continue;
                }
                col.HeaderCell.SortGlyphDirection = SortOrder.None;
            }
        }
Exemplo n.º 9
0
        public ADGVColumnHeaderCell(DataGridViewColumnHeaderCell oldCell, Boolean FilterEnabled = false)
        {
            this.Tag              = oldCell.Tag;
            this.ErrorText        = oldCell.ErrorText;
            this.ToolTipText      = oldCell.ToolTipText;
            this.Value            = oldCell.Value;
            this.ValueType        = oldCell.ValueType;
            this.ContextMenuStrip = oldCell.ContextMenuStrip;
            this.Style            = oldCell.Style;
            this.filterEnabled    = FilterEnabled;

            ADGVColumnHeaderCell oldADGVCell = oldCell as ADGVColumnHeaderCell;

            if (oldADGVCell != null && oldADGVCell.FilterMenu != null)
            {
                this.FilterMenu               = oldADGVCell.FilterMenu;
                this.filterImage              = oldADGVCell.filterImage;
                this.filterButtonPressed      = oldADGVCell.filterButtonPressed;
                this.filterButtonOver         = oldADGVCell.filterButtonOver;
                this.filterButtonOffsetBounds = oldADGVCell.filterButtonOffsetBounds;
                this.filterButtonImageBounds  = oldADGVCell.filterButtonImageBounds;

                this.FilterMenu.FilterChanged += new EventHandler(FilterMenu_FilterChanged);
                this.FilterMenu.SortChanged   += new EventHandler(FilterMenu_SortChanged);
            }
            else
            {
                this.FilterMenu = new ADGVFilterMenu(oldCell.OwningColumn.ValueType);
                this.FilterMenu.FilterChanged += new EventHandler(FilterMenu_FilterChanged);
                this.FilterMenu.SortChanged   += new EventHandler(FilterMenu_SortChanged);
            }
        }
Exemplo n.º 10
0
            /// <summary>
            /// Latest
            /// </summary>
            /// <param name="DGV"></param>
            /// <param name="DGVStartFromColumn"></param>
            /// <param name="Comment">same lenght as parencolumnname</param>
            /// <param name="ParentRelation"></param>
            /// <param name="ParentColumnNameWithTipData"></param>
            public static void ColumnHeaderWithCommonRowDataFrom(ref DataGridView DGV, int DGVStartFromColumn, string[] Comment, string ParentRelation, string[] ParentColumnNameWithTipData)
            {
                HashSet <int> set = new HashSet <int>();
                IEnumerable <DataGridViewCell> cells = Selected(DGV, true);

                cells = cells.Where(CellsFromCol(DGVStartFromColumn));
                cells = cells.Where(o => set.Add(o.ColumnIndex)).ToList();

                foreach (DataGridViewCell cell in cells)
                {
                    DataRow tag    = (DataRow)cell.Tag;
                    DataRow parent = tag.GetParentRow(ParentRelation);
                    if (parent == null)
                    {
                        continue;
                    }

                    DataGridViewColumnHeaderCell headerCell = cell.OwningColumn.HeaderCell;
                    int subcount = ParentColumnNameWithTipData.Count();
                    for (int i = 0; i < subcount; i++)
                    {
                        string com     = Comment[i];
                        string ptip    = ParentColumnNameWithTipData[i];
                        string ptipval = parent[ptip].ToString();
                        headerCell.ToolTipText += com + ptipval + "\n";
                    }
                }
                set.Clear();
                set   = null;
                cells = null;
                DGV.ClearSelection();
            }
Exemplo n.º 11
0
    public void DisplayResults(DataGridView DataView)
    {
        DataGridViewColumn           col    = default(DataGridViewColumn);
        DataGridViewRow              row    = default(DataGridViewRow);
        DataGridViewCell             cell   = default(DataGridViewCell);
        DataGridViewColumnHeaderCell header = default(DataGridViewColumnHeaderCell);
        int Index = 0;

        ReadIndex = -1;

        DataView.Rows.Clear();
        DataView.Columns.Clear();

        for (Index = 0; Index <= FieldCount - 1; Index++)
        {
            col = new DataGridViewColumn();
            col.CellTemplate = new DataGridViewTextBoxCell();
            header           = new DataGridViewColumnHeaderCell();
            header.Value     = GetName(Index);
            col.HeaderCell   = header;
            DataView.Columns.Add(col);
        }

        while (Read())
        {
            row = new DataGridViewRow();
            for (Index = 0; Index <= FieldCount - 1; Index++)
            {
                cell       = new DataGridViewTextBoxCell();
                cell.Value = GetString(Index).ToString();
                row.Cells.Add(cell);
            }
            DataView.Rows.Add(row);
        }
    }
Exemplo n.º 12
0
        /// <summary>
        /// 初始化 DataGridViewColumnHeadErCell 类的新实例,并将其属性值设置为指定 DataGridViewColumnHeadErCell 的属性值。
        /// </summary>
        /// <param name="oldHeaderCell">DataGridViewColumnHeadErCell 可从 中复制属性值。</param>
        public DataGridViewAutoFilterColumnHeaderCell(DataGridViewColumnHeaderCell oldHeaderCell)
        {
            ContextMenuStrip = oldHeaderCell.ContextMenuStrip;
            ErrorText        = oldHeaderCell.ErrorText;
            Tag         = oldHeaderCell.Tag;
            ToolTipText = oldHeaderCell.ToolTipText;
            Value       = oldHeaderCell.Value;
            ValueType   = oldHeaderCell.ValueType;

            // 在以前未设置 Style 属性时,使用 HasStyle 避免创建新样式对象。
            if (oldHeaderCell.HasStyle)
            {
                Style = oldHeaderCell.Style;
            }
            //如果旧单元格是自动筛选器单元格,请复制此类型的属性。 这使 Clone 方法能够重用此构造函数。
            DataGridViewAutoFilterColumnHeaderCell filterCell =
                oldHeaderCell as DataGridViewAutoFilterColumnHeaderCell;

            if (filterCell != null)
            {
                FilteringEnabled                   = filterCell.FilteringEnabled;
                AutomaticSortingEnabled            = filterCell.AutomaticSortingEnabled;
                currentDropDownButtonPaddingOffset =
                    filterCell.currentDropDownButtonPaddingOffset;
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Initializes a new instance of the DataGridViewColumnHeaderCell
        /// class and sets its property values to the property values of the
        /// specified DataGridViewColumnHeaderCell.
        /// </summary>
        /// <param name="oldHeaderCell">The DataGridViewColumnHeaderCell to copy property values from.</param>
        public DataGridViewAutoFilterMultiColumnHeaderCell(DataGridViewColumnHeaderCell oldHeaderCell) : base(oldHeaderCell)
        {
            this.ContextMenuStrip = oldHeaderCell.ContextMenuStrip;
            this.ErrorText        = oldHeaderCell.ErrorText;
            this.Tag         = oldHeaderCell.Tag;
            this.ToolTipText = oldHeaderCell.ToolTipText;
            this.Value       = oldHeaderCell.Value;
            this.ValueType   = oldHeaderCell.ValueType;

            // Use HasStyle to avoid creating a new style object
            // when the Style property has not previously been set.
            if (oldHeaderCell.HasStyle)
            {
                this.Style = oldHeaderCell.Style;
            }

            // Copy this type's properties if the old cell is an auto-filter cell.
            // This enables the Clone method to reuse this constructor.
            DataGridViewAutoFilterMultiColumnHeaderCell filterCell =
                oldHeaderCell as DataGridViewAutoFilterMultiColumnHeaderCell;

            if (filterCell != null)
            {
                this.FilteringEnabled                   = filterCell.FilteringEnabled;
                this.AutomaticSortingEnabled            = filterCell.AutomaticSortingEnabled;
                this.DropDownListBoxMaxLines            = filterCell.DropDownListBoxMaxLines;
                this.currentDropDownButtonPaddingOffset =
                    filterCell.currentDropDownButtonPaddingOffset;
            }
        }
Exemplo n.º 14
0
        public DataGridViewAutoFilterColumnHeaderCell(DataGridViewColumnHeaderCell oldHeaderCell)
        {
            this.filters                      = new OrderedDictionary();
            this.selectedFilterValue          = string.Empty;
            this.currentColumnFilter          = string.Empty;
            this.dropDownButtonBoundsValue    = Rectangle.Empty;
            this.filteringEnabledValue        = true;
            this.automaticSortingEnabledValue = true;
            this.dropDownListBoxMaxLinesValue = 20;
            this.ContextMenuStrip             = oldHeaderCell.ContextMenuStrip;
            base.ErrorText                    = oldHeaderCell.ErrorText;
            base.Tag         = oldHeaderCell.Tag;
            base.ToolTipText = oldHeaderCell.ToolTipText;
            base.Value       = oldHeaderCell.Value;
            this.ValueType   = oldHeaderCell.ValueType;
            if (oldHeaderCell.HasStyle)
            {
                base.Style = oldHeaderCell.Style;
            }
            DataGridViewAutoFilterColumnHeaderCell cell = oldHeaderCell as DataGridViewAutoFilterColumnHeaderCell;

            if (cell != null)
            {
                this.FilteringEnabled                   = cell.FilteringEnabled;
                this.AutomaticSortingEnabled            = cell.AutomaticSortingEnabled;
                this.DropDownListBoxMaxLines            = cell.DropDownListBoxMaxLines;
                this.currentDropDownButtonPaddingOffset = cell.currentDropDownButtonPaddingOffset;
            }
        }
Exemplo n.º 15
0
        public static void CopyGrid2Clip(DataGridView g1)
        {
            bool hRowVis = g1.RowHeadersVisible;
            bool hColVis = g1.ColumnHeadersVisible;

            string result = "";
            string value  = "";

            //Header
            if (hColVis)
            {
                result = result + "\t";
            }

            foreach (DataGridViewColumn column in g1.Columns)
            {
                DataGridViewColumnHeaderCell headerCell = column.HeaderCell;
                string headerCaptionText = column.HeaderText;
                result = result + headerCaptionText + "\t";
            }
            result = result + "\n";

            //Body
            for (int x = 0; x < g1.RowCount; x++)
            {
                if (hColVis)
                {
                    value = "";
                    try
                    { value = g1.Rows[x].HeaderCell.Value.ToString(); }
                    catch (Exception ex)
                    {
                        if (ex.Message == "")
                        {
                            value = "";
                        }
                    }

                    result = result + value + "\t";
                }

                for (int y = 0; y < g1.ColumnCount; y++)
                {
                    value = g1.Rows[x].Cells[y].FormattedValue.ToString();
                    //value = value.Replace("/n", "");
                    //value = value.Replace("/r", "");
                    //value = value.Replace("/t", "");
                    value = value.Replace(char.ConvertFromUtf32(30), "");
                    value = value.Replace(char.ConvertFromUtf32(10), "");
                    value = value.Replace(char.ConvertFromUtf32(13), "");

                    result = result + value + "\t";
                }
                result = result + "\n";
            }
            Clipboard.Clear();
            Clipboard.SetDataObject(result);
            MessageBox.Show("Data grid was copied into clipboard!");
        }
Exemplo n.º 16
0
        static public DataGridViewColumnHeaderCell GetDataGridViewColumnHeaderCell(string Text)
        {
            var cell = new DataGridViewColumnHeaderCell();

            cell.Style.Font = defaultFont;
            cell.Value      = Text;
            return(cell);
        }
Exemplo n.º 17
0
        private DataGridViewDropdownColumnHeaderCell CreateDropdownHeaderCell(
            DataGridViewColumnHeaderCell oldHeaderCell, SortedList <int, string> columnOptions)
        {
            var cell = new DataGridViewDropdownColumnHeaderCell(oldHeaderCell, columnOptions);

            cell.MenuItemClicked += cell_MenuItemClicked;
            return(cell);
        }
        /// <summary>
        /// Initializes a new instance of the DataGridViewColumnHeaderCell
        /// class and sets its property values to the property values of the
        /// specified DataGridViewColumnHeaderCell.
        /// </summary>
        /// <param name="oldHeaderCell">The DataGridViewColumnHeaderCell to copy property values from.</param>
        public DataGridViewAutoFilterDateTimeColumnHeaderCell(DataGridViewColumnHeaderCell oldHeaderCell) : base(oldHeaderCell)
        {
            m_dtpBefore.Value = DateTime.UtcNow.Date + new TimeSpan(23, 59, 59);
            m_dtpAfter.Value  = new DateTime(2000, 1, 1, 0, 0, 0);

            m_dtpBefore.Checked = false;
            m_dtpAfter.Checked  = false;
        }
Exemplo n.º 19
0
    public static object CloneObject(this DataGridViewColumnHeaderCell myObj)
    {
        DataGridViewColumnHeaderCell clonedObject = new DataGridViewColumnHeaderCell();

        clonedObject.ColumnIndex = myObj.ColumnIndex;

        return(clonedObject);
    }
Exemplo n.º 20
0
        private void sorting(object sender, DataGridViewCellMouseEventArgs e)
        {
            DataGridViewColumnHeaderCell header = this.dataGridView1.Columns[e.ColumnIndex].HeaderCell;
            DataGridViewColumn           column = header.OwningColumn;
            DataTable table = this.dataGridView1.DataSource as DataTable;



            if (previousSort == null)
            {
                previousSort           = column;
                currentSort            = column;
                table.DefaultView.Sort = column.Name + currentSortMode;
            }
            else
            {
                if (previousSort == currentSort)
                {
                    if (column == currentSort)
                    {
                        currentSortMode = currentSortMode == " ASC " ? " DESC " : " ASC ";
                        currentSort.HeaderCell.SortGlyphDirection = currentSort.HeaderCell.SortGlyphDirection == SortOrder.Ascending ? SortOrder.Descending : SortOrder.Ascending;
                        previousSortMode       = currentSortMode;
                        table.DefaultView.Sort = currentSort.Name + currentSortMode;
                    }
                    else
                    {
                        currentSort     = column;
                        currentSortMode = " ASC ";
                        currentSort.HeaderCell.SortGlyphDirection = SortOrder.Ascending;
                        table.DefaultView.Sort = previousSort.Name + previousSortMode + " , " + currentSort.Name + currentSortMode;
                    }
                }
                else
                {
                    if (currentSort == column)
                    {
                        currentSortMode = currentSortMode == " ASC " ? " DESC " : " ASC ";

                        currentSort.HeaderCell.SortGlyphDirection = currentSort.HeaderCell.SortGlyphDirection == SortOrder.Ascending ? SortOrder.Descending : SortOrder.Ascending;
                    }
                    else
                    {
                        previousSort = currentSort;

                        previousSort.HeaderCell.SortGlyphDirection = previousSort.HeaderCell.SortGlyphDirection == SortOrder.Ascending ? SortOrder.Descending : SortOrder.Ascending;
                        currentSort      = column;
                        previousSortMode = currentSortMode;
                        currentSortMode  = " ASC ";

                        currentSort.HeaderCell.SortGlyphDirection = SortOrder.Ascending;
                    }


                    table.DefaultView.Sort = previousSort.Name + previousSortMode + " , " + currentSort.Name + currentSortMode;
                }
            }
        }
Exemplo n.º 21
0
 public DataGridViewForzenColumnHeaderCell(DataGridViewColumnHeaderCell oldHeaderCell)
 {
     this.ContextMenuStrip = oldHeaderCell.ContextMenuStrip;
     this.ErrorText        = oldHeaderCell.ErrorText;
     this.Tag         = oldHeaderCell.Tag;
     this.ToolTipText = oldHeaderCell.ToolTipText;
     this.Value       = oldHeaderCell.Value;
     this.ValueType   = oldHeaderCell.ValueType;
 }
Exemplo n.º 22
0
        public void SetEvents(DataGridViewColumnHeaderCell header)
        {
            var cell = header as ColumnHeader;

            cell.SortChanged   += new ColumnHeaderCellEventHandler(cell_SortChanged);
            cell.FilterChanged += new ColumnHeaderCellEventHandler(cell_FilterChanged);
            cell.FilterPopup   += new ColumnHeaderCellEventHandler(cell_FilterPopup);
            cell.HideChanged   += new ColumnHeaderCellEventHandler(cell_HideChanged);
            cell.HexChanged    += new ColumnHeaderCellEventHandler(cell_HexChanged);
        }
Exemplo n.º 23
0
        public void SetNewHeaderCell()
        {
            var dgv = new DataGridView();
            var dvc = new DataGridViewTextBoxColumn();
            var dch = new DataGridViewColumnHeaderCell();

            dgv.Columns.Add(dvc);
            dvc.HeaderCell = dch;
            Assert.IsNotNull(dch.DataGridView, "#1");
            Assert.True(dch.ColumnIndex >= 0, "#2");
        }
Exemplo n.º 24
0
        private SortOrder InvertSortOrder(DataGridViewColumnHeaderCell headerCell)
        {
            if (headerCell.SortGlyphDirection == SortOrder.None || headerCell.SortGlyphDirection == SortOrder.Descending)
            {
                headerCell.SortGlyphDirection = SortOrder.Ascending;
                return(SortOrder.Ascending);
            }

            headerCell.SortGlyphDirection = SortOrder.Descending;
            return(SortOrder.Descending);
        }
Exemplo n.º 25
0
        public void DataGridViewColumnHeaderCellAccessibleObject_Parent_ReturnsExpected()
        {
            using DataGridView control = new();
            control.Columns.Add("Column 1", "Header text 1");
            DataGridViewColumnHeaderCell cell = control.Columns[0].HeaderCell;

            var accessibleObject = (DataGridViewColumnHeaderCellAccessibleObject)cell.AccessibilityObject;

            Assert.Equal(control.AccessibilityObject.GetChild(0), accessibleObject.Parent);
            Assert.False(control.IsHandleCreated);
        }
Exemplo n.º 26
0
        /// <summary>
        /// Handles the Column Item Clicked event of the <see cref="DataGridView"/>.
        /// </summary>
        private void MnuColumnItemClicked(object sender, EventArgs e)
        {
            ToolStripMenuItem senderItem = sender as ToolStripMenuItem;

            if (senderItem != null)
            {
                DataGridViewColumnHeaderCell headerCell = senderItem.Tag as DataGridViewColumnHeaderCell;

                if (headerCell != null && headerCell.OwningColumn != null)
                {
                    headerCell.OwningColumn.Visible = !senderItem.Checked;
                }
            }
        }
Exemplo n.º 27
0
        private IEnumerable <DataGridViewRow> Sort <T>(IEnumerable <DataGridViewRow> rows, Func <DataGridViewRow, T> sortFunction)
        {
            var get_row_mod_name = new Func <DataGridViewRow, string>(row => ((GUIMod)row.Tag).Name);
            DataGridViewColumnHeaderCell header =
                this.ModList.Columns[this.m_Configuration.SortByColumnIndex].HeaderCell;

            // The columns will be sorted by mod name in addition to whatever the current sorting column is
            if (this.m_Configuration.SortDescending)
            {
                header.SortGlyphDirection = SortOrder.Descending;
                return(rows.OrderByDescending(sortFunction).ThenBy(get_row_mod_name));
            }

            header.SortGlyphDirection = SortOrder.Ascending;
            return(rows.OrderBy(sortFunction).ThenBy(get_row_mod_name));
        }
Exemplo n.º 28
0
        private void DataGridViewResults_CellMouseUp(Object sender, DataGridViewCellMouseEventArgs e)
        {
            // ToDo: Complete Context-Menu

            ClickedRow = null;

            if (e.RowIndex >= 0)
            {
                if (e.Button == MouseButtons.Right)
                {
                    ClickedRow = dataGridViewResults.Rows[e.RowIndex];
                    contextMenuStrip.Show(MousePosition);
                    //contextMenuStrip.Show(dataGridViewResults[e.ColumnIndex, e.RowIndex].;
                }
            }
            else if (e.RowIndex == -1)
            {
                if (dataGridViewResults.RowCount > 0)
                {
                    DataGridViewColumn col = dataGridViewResults.Columns[e.ColumnIndex];

                    ListSortDirection sortDirection = ListSortDirection.Ascending;
                    if (dataGridViewResults.SortedColumn == col &&
                        dataGridViewResults.SortOrder == SortOrder.Ascending)
                    {
                        sortDirection = ListSortDirection.Descending;
                    }

                    DataGridViewResults_BeginEdit(true, false);
                    dataGridViewResults.Sort(col, sortDirection);
                    DataGridViewResults_EndEdit(true, false);

                    foreach (DataGridViewColumn c in dataGridViewResults.Columns)
                    {
                        DataGridViewColumnHeaderCell headerCell = c.HeaderCell;
                        if (headerCell != col.HeaderCell)
                        {
                            headerCell.SortGlyphDirection = SortOrder.None;
                        }
                    }

                    col.HeaderCell.SortGlyphDirection = dataGridViewResults.SortOrder;
                }
            }
        }
Exemplo n.º 29
0
        private void UpdateResources()
        {
            this.mResourceCount  = 0;
            this.resDGV.RowCount = 0;
            this.okBTN.Enabled   = false;

            if (this.mSelectedPackage != null)
            {
                this.mResourceCount
                    = this.mSelectedPackage.Entries.Length;
                if (this.mResources.Length < this.mResourceCount)
                {
                    this.mResources
                        = new ResourceMgr.ResEntry[this.mResourceCount];
                }
                Array.Copy(this.mSelectedPackage.Entries, 0,
                           this.mResources, 0, this.mResourceCount);

                switch (this.mColIndex)
                {
                case 0:
                    Array.Sort(this.mResources, 0,
                               this.mResourceCount, sIIDComparer);
                    break;

                case 1:
                    Array.Sort(this.mResources, 0,
                               this.mResourceCount, sGIDComparer);
                    break;

                case 2:
                    Array.Sort(this.mResources, 0,
                               this.mResourceCount, sNameComparer);
                    break;
                }
                DataGridViewColumnHeaderCell hc
                    = this.resDGV.Columns[this.mColIndex].HeaderCell;
                if (hc.SortGlyphDirection == SortOrder.Descending)
                {
                    Array.Reverse(this.mResources, 0, this.mResourceCount);
                }
                this.resDGV.RowCount = this.mResourceCount;
            }
        }
        public void DataGridViewColumnCollection_AddWithHeaderCell_Invoke_Success()
        {
            using var control = new DataGridView();
            DataGridViewColumnCollection collection = control.Columns;

            using var headerCell = new DataGridViewColumnHeaderCell();
            using var column     = new DataGridViewColumn(new SubDataGridViewCell())
                  {
                      HeaderCell = headerCell
                  };

            // Add one.
            collection.Add(column);
            Assert.Same(control, column.DataGridView);
            Assert.Equal(0, column.Index);
            Assert.Equal(0, column.DisplayIndex);
            Assert.Same(control, headerCell.DataGridView);
            Assert.False(control.IsHandleCreated);
        }
Exemplo n.º 31
0
        private void applyFilters()
        {
            newFilter = "";

            string _product = (string)cboProduct.SelectedItem;
            string _catagory = (string)cboCatagory.SelectedItem;
            string _quantity = (string)cboQuantity.SelectedItem;
            string _price = (string)cboPrice.SelectedItem;
            string _reorder = (string)cboReorder.SelectedItem;

            if (!string.IsNullOrEmpty(_product) && _product != "(All)")
            {
                dgvHeader = _dataGridView.Columns["ProductName"].HeaderCell;
                setFilter(_product);
            }

            if (!string.IsNullOrEmpty(_catagory) && _catagory != "(All)")
            {
                dgvHeader = _dataGridView.Columns["CatagoryName"].HeaderCell;
                setFilter(_catagory);
            }

            if (!string.IsNullOrEmpty(_quantity) && _quantity != "(All)")
            {
                dgvHeader = _dataGridView.Columns["QuantityPerUnit"].HeaderCell;
                setFilter(_quantity);
            }

            if (!string.IsNullOrEmpty(_price) && _price != "(All)")
            {
                dgvHeader = _dataGridView.Columns["UnitPrice"].HeaderCell;
                setFilter(_price);
            }

            if (!string.IsNullOrEmpty(_reorder) && _reorder != "(All)")
            {
                dgvHeader = _dataGridView.Columns["ReorderLevel"].HeaderCell;
                setFilter(_reorder);
            }

            // Only discontinuted items
            if (rbtnDiscontinuedProducts.Checked)
            {
                dgvHeader = _dataGridView.Columns["Discontinued"].HeaderCell;
                setFilter("(True)");
            }

            // Only non-suspended tasks
            if (rbtnOpenProducts.Checked)
            {
                dgvHeader = _dataGridView.Columns["Discontinued"].HeaderCell;
                setFilter("(False)");
            }

            // Set the filter
            try
            {
                data.Filter = newFilter;
            }
            catch (InvalidExpressionException ex)
            {
                MessageBox.Show("Product Filter", "Error setting filter: " + ex.ToString());
            }
            this.Close();
        }
Exemplo n.º 32
0
        private void catagoryPopulateFilter()
        {
            dgvHeader = _dataGridView.Columns["CatagoryName"].HeaderCell;
            PopulateFilter(catagoryFilters);

            String[] filterArray = new String[catagoryFilters.Count];
            catagoryFilters.Keys.CopyTo(filterArray, 0);
            cboCatagory.Items.Clear();
            cboCatagory.Items.AddRange(filterArray);
        }
Exemplo n.º 33
0
        private void productPopulateFilter()
        {
            dgvHeader = _dataGridView.Columns["ProductName"].HeaderCell;
            PopulateFilter(productFilters);

            String[] filterArray = new String[productFilters.Count];
            productFilters.Keys.CopyTo(filterArray, 0);
            cboProduct.Items.Clear();
            cboProduct.Items.AddRange(filterArray);
        }
Exemplo n.º 34
0
        private void quantityPopulateFilter()
        {
            dgvHeader = _dataGridView.Columns["QuantityPerUnit"].HeaderCell;
            PopulateFilter(QuantityFilters);

            String[] filterArray = new String[QuantityFilters.Count];
            QuantityFilters.Keys.CopyTo(filterArray, 0);
            cboQuantity.Items.Clear();
            cboQuantity.Items.AddRange(filterArray);
        }
Exemplo n.º 35
0
        private void reorderPopulateFilter()
        {
            dgvHeader = _dataGridView.Columns["ReorderLevel"].HeaderCell;
            PopulateFilter(reorderFilters);

            String[] filterArray = new String[reorderFilters.Count];
            reorderFilters.Keys.CopyTo(filterArray, 0);
            cboReorder.Items.Clear();
            cboReorder.Items.AddRange(filterArray);
        }
Exemplo n.º 36
0
        private void setCurrentFilters()
        {
            cboProduct.SelectedItem = "(All)";
            cboCatagory.SelectedItem = "(All)";
            cboQuantity.SelectedItem = "(All)";
            cboPrice.SelectedItem = "(All)";
            cboReorder.SelectedItem = "(All)";

            int index1;

            // Disable any excluded columns
            index1 = excludeColumns.IndexOf("ProductName");
            if (index1 != -1) { cboProduct.Enabled = false; }
            index1 = excludeColumns.IndexOf("CatagoryName");
            if (index1 != -1) { cboCatagory.Enabled = false; }
            index1 = excludeColumns.IndexOf("QuantityPerUnit");
            if (index1 != -1) { cboQuantity.Enabled = false; }
            index1 = excludeColumns.IndexOf("UnitPrice");
            if (index1 != -1) { cboPrice.Enabled = false; }
            index1 = excludeColumns.IndexOf("ReorderLevel");
            if (index1 != -1) { cboReorder.Enabled = false; }

            // Get current filter string
            string filterString = oldFilter;
            // If nothing filtered, return
            if (string.IsNullOrEmpty(filterString)) { return; }

            index1 = excludeColumns.IndexOf("ProductName");
            if (index1 == -1)
            {
                dgvHeader = _dataGridView.Columns["ProductName"].HeaderCell;
                cboProduct.SelectedItem = getFilter(filterString);
            }
            else
            {
                cboProduct.Enabled = false;
            }

            index1 = excludeColumns.IndexOf("CatagoryName");
            if (index1 == -1)
            {
                dgvHeader = _dataGridView.Columns["CatagoryName"].HeaderCell;
                cboCatagory.SelectedItem = getFilter(filterString);
            }
            else
            {
                cboCatagory.Enabled = false;
            }

            index1 = excludeColumns.IndexOf("QuantityPerUnit");
            if (index1 == -1)
            {
                dgvHeader = _dataGridView.Columns["QuantityPerUnit"].HeaderCell;
                cboQuantity.SelectedItem = getFilter(filterString);
            }
            else
            {
                cboQuantity.Enabled = false;
            }

            index1 = excludeColumns.IndexOf("UnitPrice");
            if (index1 == -1)
            {
                dgvHeader = _dataGridView.Columns["UnitPrice"].HeaderCell;
                cboPrice.SelectedItem = getFilter(filterString);
            }
            else
            {
                cboPrice.Enabled = false;
            }

            index1 = excludeColumns.IndexOf("ReorderLevel");
            if (index1 == -1)
            {
                dgvHeader = _dataGridView.Columns["ReorderLevel"].HeaderCell;
                cboReorder.SelectedItem = getFilter(filterString);
            }
            else
            {
                cboReorder.Enabled = false;
            }
        }