/// <summary>
        ///
        /// </summary>
        private ToolStripMenuItem AutoSizeColumn(int columnIndex)
        {
            var menuItem = new ToolStripMenuItem
            {
                Text = CultureService.GetString(CultureText.menuItem_AutoSizeColumn_Text),
            };

            var lastColumns = _dataGridView.Columns.GetLastColumn(DataGridViewElementStates.Visible, DataGridViewElementStates.None);

            if (lastColumns != null)
            { /*Az utolsó oszlopra nem nyomhat autó size-t, mert akkor elvesziti az utolsó oszolp a Fill-t...*/
                if (lastColumns.Index != columnIndex)
                {
                    menuItem.Enabled = true;
                }
                else
                {
                    menuItem.Enabled = false;
                }
            }

            menuItem.Click += (o, e) =>
            {
                _dataGridView.AutoResizeColumn(columnIndex);
            };

            return(menuItem);
        }
        /// <summary>
        ///
        /// </summary>
        private ToolStripMenuItem HideColumn(int columnIndex)
        {
            var menuItem = new ToolStripMenuItem
            {
                Text    = CultureService.GetString(CultureText.menuItem_HideColumn_Text),
                Enabled = !_dataGridView.Columns[columnIndex].Frozen
            };

            menuItem.Click += (o, e) =>
            {
                var newColumnLayout = new ColumnLayoutCollection();
                foreach (var layout in _dataGridView.ColumnLayout)
                {
                    newColumnLayout.Add(layout);
                }

                var toHideColumn = newColumnLayout.FirstOrDefault(n => n.Name == _dataGridView.ColumnLayout[columnIndex].Name);
                if (toHideColumn != null)
                {
                    toHideColumn.Visible = false;
                }

                _dataGridView.ColumnLayout = newColumnLayout;
            };

            return(menuItem);
        }
        /// <summary>
        ///
        /// </summary>
        private ToolStripMenuItem ShowAll()
        {
            var menuItem = new ToolStripMenuItem
            {
                Text = CultureService.GetString(CultureText.menuItem_ShowAll_Text),
            };

            menuItem.Click += (o, e) =>
            {
                _dataGridView.ShowAllColums();
            };

            return(menuItem);
        }
Example #4
0
        protected KnvDataGridViewNewRowBaseCommand(DataGridView dataGridView, IBindingList collection)
        {
            // ReSharper disable once DoNotCallOverridableMethodsInConstructor
            Image = Resources.New_24x24;
            // ReSharper disable once DoNotCallOverridableMethodsInConstructor
            Text = CultureService.GetString(CultureText.menuItem_New_Text);

            if (dataGridView.ContextMenuStrip == null)
            {
                throw new ArgumentNullException(@"dataGridView", @"DataGridView-nak mar kellne, hogy legyen ContextMenuStrip-je!");
            }
            _collection   = collection;
            _dataGridView = dataGridView;
            dataGridView.ContextMenuStrip.Opening += new CancelEventHandler(ContextMenuStrip_Opening);
        }
        /// <summary>
        ///
        /// </summary>
        private ToolStripMenuItem AutoSizeAll()
        {
            var menuItem = new ToolStripMenuItem
            {
                Text = CultureService.GetString(CultureText.menuItem_AutoSizeAll_Text),
            };

            menuItem.Click += (o, e) =>
            {
                Cursor.Current = Cursors.WaitCursor;
                _dataGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.DisplayedCells);
                Cursor.Current = Cursors.Default;
            };

            return(menuItem);
        }
Example #6
0
        protected KnvDataGridViewPasteRowsBaseCommand(DataGridView dataGridView, IBindingList collection)
        {
            // ReSharper disable once DoNotCallOverridableMethodsInConstructor
            Text = CultureService.GetString(CultureText.menuItem_Paste_Text);
            // ReSharper disable once DoNotCallOverridableMethodsInConstructor
            Image        = Resources.Paste_24x24;
            ShortcutKeys = Keys.Control | Keys.V;

            if (dataGridView.ContextMenuStrip == null)
            {
                throw new ArgumentNullException(@"dataGridView", @"DataGridView-nak mar kellne, hogy legyen ContextMenuStrip-je!");
            }
            _collection         = collection;
            _dataGridView       = dataGridView;
            _retviredDataObject = Clipboard.GetDataObject();
            dataGridView.ContextMenuStrip.Opening += new CancelEventHandler(ContextMenuStrip_Opening);
        }
        /// <summary>
        /// Context menu a DataGridView oszlopainak fejlécéhez.
        /// FIGYELEM Csak azokat oszlopokoat lehet elmenteni amiknek van nevük
        /// </summary>
        /// <param name="columnIndex">Erre a fejléc indexre kattintott.</param>
        /// <returns>Context menu, ezt jelenísd meg.</returns>
        private ContextMenuStrip CreateColumnHeaderContextMenuStrip(int columnIndex)
        {
            var contextMenu = new ContextMenuStrip();

            #region Hide Column

            var hideColumnStripItem = new ToolStripMenuItem
            {
                Text    = CultureService.GetString(CultureText.menuItem_HideColumn_Text),
                Enabled = !Columns[columnIndex].Frozen
            };


            hideColumnStripItem.Click += (o, e) =>
            {
                var newColumnLayout = new ColumnLayoutCollection();
                foreach (var layout in ColumnLayout)
                {
                    newColumnLayout.Add(layout);
                }

                var toHideColumn = newColumnLayout.FirstOrDefault(n => n.Name == Columns[columnIndex].Name);
                if (toHideColumn != null)
                {
                    toHideColumn.Visible = false;
                }

                ColumnLayout = newColumnLayout;
                /*TODO: Túl hosszú múvelet.*/
                /*AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);*/
            };
            contextMenu.Items.Add(hideColumnStripItem);
            #endregion

            #region Auto Size Column

            var autoSizeColumnStripItem = new ToolStripMenuItem
            {
                Text = CultureService.GetString(CultureText.menuItem_AutoSizeColumn_Text),
            };

            var lastColumns = Columns.GetLastColumn(DataGridViewElementStates.Visible, DataGridViewElementStates.None);
            if (lastColumns != null)
            { /*Az utolsó oszlopra nem nyomhat autó size-t, mert akkor elvesziti az utolsó oszolp a Fill-t...*/
                if (lastColumns.Index != columnIndex)
                {
                    autoSizeColumnStripItem.Enabled = true;
                }
                else
                {
                    autoSizeColumnStripItem.Enabled = false;
                }
            }

            autoSizeColumnStripItem.Click += (o, e) =>
            {
                AutoResizeColumn(columnIndex);
            };
            contextMenu.Items.Add(autoSizeColumnStripItem);
            #endregion

            contextMenu.Items.Add("-");

            #region Show All

            var showAllItem = new ToolStripMenuItem
            {
                Text = CultureService.GetString(CultureText.menuItem_ShowAll_Text),
            };
            showAllItem.Click += (o, e) =>
            {
                ShowAllColums();
            };
            contextMenu.Items.Add(showAllItem);
            #endregion

            #region Auto Size All

            var autoSizeAllItem = new ToolStripMenuItem
            {
                Text = CultureService.GetString(CultureText.menuItem_AutoSizeAll_Text),
            };
            autoSizeAllItem.Click += (o, e) =>
            {
                Cursor.Current = Cursors.WaitCursor;
                AutoResizeColumns(DataGridViewAutoSizeColumnsMode.DisplayedCells);
                Cursor.Current = Cursors.Default;
            };
            contextMenu.Items.Add(autoSizeAllItem);
            #endregion

            contextMenu.Items.Add("-");

            #region Column Name checkButton
            foreach (DataGridViewColumn gridColumn in this.Columns)
            {
                if (gridColumn.HeaderText != @"Index")
                {
                    var button = new ToolStripMenuItem
                    {
                        Text         = gridColumn.HeaderText,
                        CheckOnClick = true,
                        CheckState   = gridColumn.Visible ? CheckState.Checked : CheckState.Unchecked
                    };
                    var column = gridColumn;
                    button.CheckStateChanged += (o, ev) =>
                    {
                        column.Visible = button.CheckState == CheckState.Checked ? true : false;
                    };
                    contextMenu.Items.Add(button);
                }
            }
            #endregion

            return(contextMenu);
        }