Exemple #1
0
        /// <summary>
        ///   Sets the auto-size mode for the rows.
        /// </summary>
        ///
        public DataGridBox SetAutoSizeRows(DataGridViewAutoSizeRowsMode mode)
        {
            if (this.InvokeRequired)
            {
                this.Invoke((Action)(() => SetAutoSizeRows(mode)));
                return(this);
            }

            dataGridView.AutoSizeRowsMode = mode;

            return(this);
        }
        /// <summary>
        /// Set whether or not the grid which this adapter is linked to should automatically resize itself.
        /// </summary>
        /// <param name="mode">Whether or not the grid should automatically resize itself.</param>
        public void SetGridLayoutMode(GridLayoutMode mode)
        {
            switch (mode)
            {
            case GridLayoutMode.Automatic:
            default:
                _newColumnAutoSizeColumnMode = DataGridViewAutoSizeColumnsMode.DisplayedCells;
                _newRowAutoSizeRowMode       = DataGridViewAutoSizeRowsMode.DisplayedCells;
                break;

            case GridLayoutMode.Frozen:
                _newColumnAutoSizeColumnMode = DataGridViewAutoSizeColumnsMode.None;
                _newRowAutoSizeRowMode       = DataGridViewAutoSizeRowsMode.None;
                break;
            }

            ResetAllColumnAutoSizeModes();
        }
Exemple #3
0
		public DataGridView ()
		{
			SetStyle (ControlStyles.Opaque, true);
			//SetStyle (ControlStyles.UserMouse, true);
			SetStyle (ControlStyles.OptimizedDoubleBuffer, true);
			
			adjustedTopLeftHeaderBorderStyle = new DataGridViewAdvancedBorderStyle();
			adjustedTopLeftHeaderBorderStyle.All = DataGridViewAdvancedCellBorderStyle.Single;
			advancedCellBorderStyle = new DataGridViewAdvancedBorderStyle();
			advancedCellBorderStyle.All = DataGridViewAdvancedCellBorderStyle.Single;
			advancedColumnHeadersBorderStyle = new DataGridViewAdvancedBorderStyle();
			advancedColumnHeadersBorderStyle.All = DataGridViewAdvancedCellBorderStyle.Single;
			advancedRowHeadersBorderStyle = new DataGridViewAdvancedBorderStyle();
			advancedRowHeadersBorderStyle.All = DataGridViewAdvancedCellBorderStyle.Single;
			alternatingRowsDefaultCellStyle = new DataGridViewCellStyle();
			allowUserToAddRows = true;
			allowUserToDeleteRows = true;
			allowUserToOrderColumns = false;
			allowUserToResizeColumns = true;
			allowUserToResizeRows = true;
			autoGenerateColumns = true;
			autoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
			autoSizeRowsMode = DataGridViewAutoSizeRowsMode.None;
			backColor = Control.DefaultBackColor;
			backgroundColor = SystemColors.AppWorkspace;
			borderStyle = BorderStyle.FixedSingle;
			cellBorderStyle = DataGridViewCellBorderStyle.Single;
			clipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithAutoHeaderText;
			columnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single;
			columnHeadersDefaultCellStyle = new DataGridViewCellStyle();
			columnHeadersDefaultCellStyle.BackColor = SystemColors.Control;
			columnHeadersDefaultCellStyle.ForeColor = SystemColors.WindowText;
			columnHeadersDefaultCellStyle.SelectionBackColor = SystemColors.Highlight;
			columnHeadersDefaultCellStyle.SelectionForeColor = SystemColors.HighlightText;
			columnHeadersDefaultCellStyle.Font = this.Font;
			columnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
			columnHeadersDefaultCellStyle.WrapMode = DataGridViewTriState.True;
			columnHeadersHeight = 23;
			columnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing;
			columnHeadersVisible = true;
			columns = CreateColumnsInstance();
			columns.CollectionChanged += OnColumnCollectionChanged;
			currentCellAddress = new Point (-1, -1);
			dataMember = String.Empty;
			defaultCellStyle = new DataGridViewCellStyle();
			defaultCellStyle.BackColor = SystemColors.Window;
			defaultCellStyle.ForeColor = SystemColors.ControlText;
			defaultCellStyle.SelectionBackColor = SystemColors.Highlight;
			defaultCellStyle.SelectionForeColor = SystemColors.HighlightText;
			defaultCellStyle.Font = this.Font;
			defaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
			defaultCellStyle.WrapMode = DataGridViewTriState.False;
			editMode = DataGridViewEditMode.EditOnKeystrokeOrF2;
			firstDisplayedScrollingColumnHiddenWidth = 0;
			isCurrentCellDirty = false;
			multiSelect = true;
			readOnly = false;
			rowHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single;
			rowHeadersDefaultCellStyle = (DataGridViewCellStyle) columnHeadersDefaultCellStyle.Clone ();
			rowHeadersVisible = true;
			rowHeadersWidth = 41;
			rowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.EnableResizing;
			rows = CreateRowsInstance();
			rowsDefaultCellStyle = new DataGridViewCellStyle();
			selectionMode = DataGridViewSelectionMode.RowHeaderSelect;
			showCellErrors = true;
			showEditingIcon = true;
			scrollBars = ScrollBars.Both;
			userSetCursor = Cursor.Current;
			virtualMode = false;

			horizontalScrollBar = new HScrollBar();
			horizontalScrollBar.Scroll += OnHScrollBarScroll;
			horizontalScrollBar.Visible = false;
			
			verticalScrollBar = new VScrollBar();
			verticalScrollBar.Scroll += OnVScrollBarScroll;
			verticalScrollBar.Visible = false;
			
			Controls.AddRange (new Control[] {horizontalScrollBar, verticalScrollBar});
		}
Exemple #4
0
		public void AutoResizeRows (DataGridViewAutoSizeRowsMode autoSizeRowsMode)
		{
			if (!Enum.IsDefined(typeof(DataGridViewAutoSizeRowsMode), autoSizeRowsMode))
				throw new InvalidEnumArgumentException ("Parameter autoSizeRowsMode is not a valid DataGridViewRowsMode.");
			if ((autoSizeRowsMode == DataGridViewAutoSizeRowsMode.AllHeaders || autoSizeRowsMode == DataGridViewAutoSizeRowsMode.DisplayedHeaders) && rowHeadersVisible == false)
				throw new InvalidOperationException ("Parameter autoSizeRowsMode cannot be AllHeaders or DisplayedHeaders in this DataGridView.");
			if (autoSizeRowsMode == DataGridViewAutoSizeRowsMode.None)
				throw new ArgumentException ("Parameter autoSizeRowsMode cannot be None.");
			
			AutoResizeRows (autoSizeRowsMode, false);
		}
        /// <include file='doc\DataGridView.uex' path='docs/doc[@for="DataGridView.AutoResizeRows2"]/*' />
        protected void AutoResizeRows(DataGridViewAutoSizeRowsMode autoSizeRowsMode, bool fixedWidth)
        {
            switch (autoSizeRowsMode) 
            { 
                case DataGridViewAutoSizeRowsMode.None:
                case DataGridViewAutoSizeRowsMode.AllHeaders:
                case DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders:
                case DataGridViewAutoSizeRowsMode.AllCells:
                case DataGridViewAutoSizeRowsMode.DisplayedHeaders:
                case DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders:
                case DataGridViewAutoSizeRowsMode.DisplayedCells:
                    break;
                default: 
                    throw new InvalidEnumArgumentException("value", (int)autoSizeRowsMode, typeof(DataGridViewAutoSizeRowsMode)); 
            }

            if (autoSizeRowsMode == DataGridViewAutoSizeRowsMode.None)
            {
                throw new ArgumentException(SR.GetString(SR.DataGridView_NeedAutoSizingCriteria, "autoSizeRowsMode"));
            }

            if ((autoSizeRowsMode == DataGridViewAutoSizeRowsMode.AllHeaders || autoSizeRowsMode == DataGridViewAutoSizeRowsMode.DisplayedHeaders) &&
                !this.RowHeadersVisible)
            {
                throw new InvalidOperationException(SR.GetString(SR.DataGridView_CannotAutoSizeRowsInvisibleRowHeader));
            }

            AdjustShrinkingRows(autoSizeRowsMode, fixedWidth, false /*internalAutosizing*/);
        }
Exemple #6
0
        public static DataGridView GetDataGridView(DataGridViewSelectionMode selectionMode, DataGridViewAutoSizeRowsMode rowsSizeMode)
        {
            DataGridView grid = new DataGridView();

            grid.AllowUserToOrderColumns     = true;
            grid.AllowUserToResizeRows       = true;
            grid.AutoSizeRowsMode            = rowsSizeMode;
            grid.AllowUserToDeleteRows       = false;
            grid.AllowUserToAddRows          = false;
            grid.RowHeadersVisible           = false;
            grid.SelectionMode               = selectionMode;
            grid.MultiSelect                 = false;
            grid.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
            grid.ScrollBars      = ScrollBars.None;
            grid.BackColor       = Color.FromArgb(21, 26, 30);
            grid.BackgroundColor = Color.FromArgb(21, 26, 30);


            grid.GridColor = Color.FromArgb(17, 18, 23);
            grid.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.None;
            grid.BorderStyle = BorderStyle.None;
            DataGridViewCellStyle style = new DataGridViewCellStyle();

            style.Alignment          = DataGridViewContentAlignment.TopLeft;
            style.WrapMode           = DataGridViewTriState.True;
            style.BackColor          = Color.FromArgb(21, 26, 30);
            style.SelectionBackColor = Color.FromArgb(17, 18, 23);
            style.ForeColor          = Color.FromArgb(154, 156, 158);



            grid.DefaultCellStyle = style;
            grid.ColumnHeadersDefaultCellStyle = style;

            grid.MouseHover += delegate(object sender, EventArgs args)
            {
                grid.Focus();
            };

            grid.MouseLeave += delegate(object sender, EventArgs args)
            {
                grid.EndEdit();
            };

            grid.MouseWheel += delegate(object sender, MouseEventArgs args)
            {
                if (grid.SelectedCells.Count == 0)
                {
                    return;
                }
                int rowInd = grid.SelectedCells[0].RowIndex;
                if (args.Delta < 0)
                {
                    rowInd++;
                }
                else if (args.Delta > 0)
                {
                    rowInd--;
                }

                if (rowInd < 0)
                {
                    rowInd = 0;
                }

                if (rowInd >= grid.Rows.Count)
                {
                    rowInd = grid.Rows.Count - 1;
                }

                grid.Rows[rowInd].Selected = true;
                grid.Rows[rowInd].Cells[grid.SelectedCells[0].ColumnIndex].Selected = true;

                if (grid.FirstDisplayedScrollingRowIndex > rowInd)
                {
                    grid.FirstDisplayedScrollingRowIndex = rowInd;
                }
            };



            return(grid);
        }
        private void AdjustShrinkingRows(DataGridViewAutoSizeRowsMode autoSizeRowsMode, bool fixedWidth, bool internalAutosizing)
        {
            if ((((DataGridViewAutoSizeRowsModeInternal) autoSizeRowsMode) & DataGridViewAutoSizeRowsModeInternal.AllColumns) != 0 ||
                ((((DataGridViewAutoSizeRowsModeInternal) autoSizeRowsMode) & DataGridViewAutoSizeRowsModeInternal.Header) != 0 && this.RowHeadersVisible))
            {
                // Switch to batch operation
                this.inBulkPaintCount++;
                try
                {
                    if ((((DataGridViewAutoSizeRowsModeInternal) autoSizeRowsMode) & DataGridViewAutoSizeRowsModeInternal.AllRows) != 0)
                    {
                        // Very expensive processing - the developer should avoid this scenario.
                        this.inBulkLayoutCount++;
                        try
                        {
                            for (int rowIndex = this.Rows.GetFirstRow(DataGridViewElementStates.Visible);
                                rowIndex != -1;
                                rowIndex = this.Rows.GetNextRow(rowIndex, DataGridViewElementStates.Visible))
                            {
                                AutoResizeRowInternal(rowIndex, MapAutoSizeRowsModeToRowMode(autoSizeRowsMode), fixedWidth, internalAutosizing);
                            }
                        }
                        finally
                        {
                            ExitBulkLayout(false /*invalidInAdjustFillingColumns*/);
                        }
                    }
                    else
                    {
                        Debug.Assert((((DataGridViewAutoSizeRowsModeInternal) autoSizeRowsMode) & DataGridViewAutoSizeRowsModeInternal.DisplayedRows) != 0);
                        int displayHeight = this.layout.Data.Height;
                        int cy = 0;

                        int rowIndex = this.Rows.GetFirstRow(DataGridViewElementStates.Visible | DataGridViewElementStates.Frozen);
                        while (rowIndex != -1 && cy < displayHeight)
                        {
                            AutoResizeRowInternal(rowIndex, MapAutoSizeRowsModeToRowMode(autoSizeRowsMode), fixedWidth, internalAutosizing);
                            cy += this.Rows.SharedRow(rowIndex).GetHeight(rowIndex);
                            rowIndex = this.Rows.GetNextRow(rowIndex,
                                DataGridViewElementStates.Visible | DataGridViewElementStates.Frozen);
                        }

                        if (cy < displayHeight)
                        {
                            int cyFrozen = cy;
                            int oldFirstVisibleScrollingRow = this.displayedBandsInfo.FirstDisplayedScrollingRow;
                            rowIndex = oldFirstVisibleScrollingRow;
                            while (rowIndex != -1 && 
                                cy < displayHeight &&
                                oldFirstVisibleScrollingRow == this.displayedBandsInfo.FirstDisplayedScrollingRow)
                            {
                                AutoResizeRowInternal(rowIndex, MapAutoSizeRowsModeToRowMode(autoSizeRowsMode), fixedWidth, internalAutosizing);
                                cy += this.Rows.SharedRow(rowIndex).GetHeight(rowIndex);
                                rowIndex = this.Rows.GetNextRow(rowIndex, DataGridViewElementStates.Visible);
                            }

                            do
                            {
                                oldFirstVisibleScrollingRow = this.displayedBandsInfo.FirstDisplayedScrollingRow;
                                if (cy < displayHeight)
                                {
                                    int rowAboveFirstVisibleScrollingRow = this.Rows.GetPreviousRow(this.displayedBandsInfo.FirstDisplayedScrollingRow, DataGridViewElementStates.Visible, DataGridViewElementStates.Frozen);
                                    if (rowAboveFirstVisibleScrollingRow != -1)
                                    {
                                        AutoResizeRowInternal(rowAboveFirstVisibleScrollingRow, MapAutoSizeRowsModeToRowMode(autoSizeRowsMode), fixedWidth, internalAutosizing);
                                    }
                                }
                                cy = cyFrozen;
                                rowIndex = this.displayedBandsInfo.FirstDisplayedScrollingRow;
                                while (rowIndex != -1 && cy < displayHeight)
                                {
                                    AutoResizeRowInternal(rowIndex, MapAutoSizeRowsModeToRowMode(autoSizeRowsMode), fixedWidth, internalAutosizing);
                                    cy += this.Rows.SharedRow(rowIndex).GetHeight(rowIndex);
                                    rowIndex = this.Rows.GetNextRow(rowIndex, DataGridViewElementStates.Visible);
                                }
                            }
                            while (oldFirstVisibleScrollingRow != this.displayedBandsInfo.FirstDisplayedScrollingRow);
                        }
                    }
                }
                finally
                {
                    ExitBulkPaint(-1, -1);
                }
            }
        }
 /// <include file='doc\DataGridView.uex' path='docs/doc[@for="DataGridView.AutoResizeRows1"]/*' />
 public void AutoResizeRows(DataGridViewAutoSizeRowsMode autoSizeRowsMode)
 {
     AutoResizeRows(autoSizeRowsMode, true /*fixedWidth*/);
 }
#pragma warning restore 0414
#endif
        /// <include file='doc\DataGridView.uex' path='docs/doc[@for="DataGridView.DataGridView"]/*' />
        /// <devdoc>
        /// <para>Initializes a new instance of the <see cref='System.Windows.Forms.DataGridView'/> class.</para>
        /// </devdoc>
        public DataGridView()
        {
            SetStyle(ControlStyles.UserPaint | 
                     ControlStyles.Opaque | 
                     ControlStyles.UserMouse, true);
            
            SetStyle(ControlStyles.SupportsTransparentBackColor, false);

            // this class overrides GetPreferredSizeCore, let Control automatically cache the result
            SetState2(STATE2_USEPREFERREDSIZECACHE, true);  

            this.dataGridViewState1 = new System.Collections.Specialized.BitVector32(0x00000000);
            this.dataGridViewState2 = new System.Collections.Specialized.BitVector32(0x00000000);
            this.dataGridViewOper   = new System.Collections.Specialized.BitVector32(0x00000000);

            this.dataGridViewState1[  DATAGRIDVIEWSTATE1_columnHeadersVisible 
                                    | DATAGRIDVIEWSTATE1_rowHeadersVisible 
                                    | DATAGRIDVIEWSTATE1_autoGenerateColumns
                                    | DATAGRIDVIEWSTATE1_allowUserToAddRows
                                    | DATAGRIDVIEWSTATE1_allowUserToDeleteRows ] = true;



            this.dataGridViewState2[  DATAGRIDVIEWSTATE2_showEditingIcon
                                    | DATAGRIDVIEWSTATE2_enableHeadersVisualStyles
                                    | DATAGRIDVIEWSTATE2_mouseEnterExpected
                                    | DATAGRIDVIEWSTATE2_allowUserToResizeColumns
                                    | DATAGRIDVIEWSTATE2_allowUserToResizeRows
                                    | DATAGRIDVIEWSTATE2_showCellToolTips
                                    | DATAGRIDVIEWSTATE2_showCellErrors
                                    | DATAGRIDVIEWSTATE2_showRowErrors
                                    | DATAGRIDVIEWSTATE2_allowHorizontalScrollbar
                                    | DATAGRIDVIEWSTATE2_usedFillWeightsDirty ] = true;


            this.displayedBandsInfo = new DisplayedBandsData();
            this.lstRows = new ArrayList();

            this.converters = new Hashtable(8);
            this.pens = new Hashtable(8);
            this.brushes = new Hashtable(10);
            this.gridPen = new Pen(DefaultGridColor);

            this.selectedBandIndexes = new DataGridViewIntLinkedList();
            this.individualSelectedCells = new DataGridViewCellLinkedList();
            this.individualReadOnlyCells = new DataGridViewCellLinkedList();

            this.advancedCellBorderStyle = new DataGridViewAdvancedBorderStyle(this, 
                DataGridViewAdvancedCellBorderStyle.OutsetDouble, 
                DataGridViewAdvancedCellBorderStyle.OutsetPartial, 
                DataGridViewAdvancedCellBorderStyle.InsetDouble);
            this.advancedRowHeadersBorderStyle = new DataGridViewAdvancedBorderStyle(this);
            this.advancedColumnHeadersBorderStyle = new DataGridViewAdvancedBorderStyle(this);
            this.advancedCellBorderStyle.All = defaultAdvancedCellBorderStyle;
            this.advancedRowHeadersBorderStyle.All = defaultAdvancedRowHeadersBorderStyle;
            this.advancedColumnHeadersBorderStyle.All = defaultAdvancedColumnHeadersBorderStyle;
            this.borderStyle = defaultBorderStyle;
            this.dataGridViewState1[DATAGRIDVIEWSTATE1_multiSelect] = true;
            this.selectionMode = defaultSelectionMode;
            this.editMode = defaultEditMode;
            this.autoSizeRowsMode = DataGridViewAutoSizeRowsMode.None;
            this.autoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
            this.columnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing;
            this.rowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.EnableResizing;

            this.clipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithAutoHeaderText;

            this.layout = new LayoutData();
            this.layout.TopLeftHeader        = Rectangle.Empty;
            this.layout.ColumnHeaders        = Rectangle.Empty;
            this.layout.RowHeaders           = Rectangle.Empty;
            this.layout.ColumnHeadersVisible = true;
            this.layout.RowHeadersVisible    = true;
            this.layout.ClientRectangle      = this.ClientRectangle;

            this.scrollBars = ScrollBars.Both;

            this.horizScrollBar.RightToLeft = RightToLeft.Inherit;
            this.horizScrollBar.AccessibleName = SR.GetString(SR.DataGridView_AccHorizontalScrollBarAccName);
            this.horizScrollBar.Top = this.ClientRectangle.Height - horizScrollBar.Height;
            this.horizScrollBar.Left = 0;
            this.horizScrollBar.Visible = false;
            this.horizScrollBar.Scroll += new ScrollEventHandler(DataGridViewHScrolled);
            this.Controls.Add(this.horizScrollBar);

            this.vertScrollBar.Top = 0;
            this.vertScrollBar.AccessibleName = SR.GetString(SR.DataGridView_AccVerticalScrollBarAccName);
            this.vertScrollBar.Left = this.ClientRectangle.Width - vertScrollBar.Width;
            this.vertScrollBar.Visible = false;
            this.vertScrollBar.Scroll += new ScrollEventHandler(DataGridViewVScrolled);
            this.Controls.Add(this.vertScrollBar);

            this.ptCurrentCell = new Point(-1, -1);
            this.ptAnchorCell = new Point(-1, -1);
            this.ptMouseDownCell = new Point(-2, -2);
            this.ptMouseEnteredCell = new Point(-2, -2);
            this.ptToolTipCell = new Point(-1, -1);
            this.ptMouseDownGridCoord = new Point(-1, -1);

            this.sortOrder = SortOrder.None;

            this.lastMouseClickInfo.timeStamp = 0;

            WireScrollBarsEvents();
            PerformLayout();

            this.toolTipControl = new DataGridViewToolTip(this);
            
            Invalidate();
        }
 private void AdjustShrinkingRows(DataGridViewAutoSizeRowsMode autoSizeRowsMode, bool fixedWidth, bool internalAutosizing)
 {
     if (((autoSizeRowsMode & ((DataGridViewAutoSizeRowsMode) 2)) != DataGridViewAutoSizeRowsMode.None) || (((autoSizeRowsMode & ((DataGridViewAutoSizeRowsMode) 1)) != DataGridViewAutoSizeRowsMode.None) && this.RowHeadersVisible))
     {
         this.inBulkPaintCount++;
         try
         {
             int nextRow;
             if ((autoSizeRowsMode & ((DataGridViewAutoSizeRowsMode) 4)) != DataGridViewAutoSizeRowsMode.None)
             {
                 this.inBulkLayoutCount++;
                 try
                 {
                     for (int i = this.Rows.GetFirstRow(DataGridViewElementStates.Visible); i != -1; i = this.Rows.GetNextRow(i, DataGridViewElementStates.Visible))
                     {
                         this.AutoResizeRowInternal(i, MapAutoSizeRowsModeToRowMode(autoSizeRowsMode), fixedWidth, internalAutosizing);
                     }
                     return;
                 }
                 finally
                 {
                     this.ExitBulkLayout(false);
                 }
             }
             int height = this.layout.Data.Height;
             int num3 = 0;
             for (nextRow = this.Rows.GetFirstRow(DataGridViewElementStates.Visible | DataGridViewElementStates.Frozen); (nextRow != -1) && (num3 < height); nextRow = this.Rows.GetNextRow(nextRow, DataGridViewElementStates.Visible | DataGridViewElementStates.Frozen))
             {
                 this.AutoResizeRowInternal(nextRow, MapAutoSizeRowsModeToRowMode(autoSizeRowsMode), fixedWidth, internalAutosizing);
                 num3 += this.Rows.SharedRow(nextRow).GetHeight(nextRow);
             }
             if (num3 < height)
             {
                 int num5 = num3;
                 int firstDisplayedScrollingRow = this.displayedBandsInfo.FirstDisplayedScrollingRow;
                 nextRow = firstDisplayedScrollingRow;
                 while (((nextRow != -1) && (num3 < height)) && (firstDisplayedScrollingRow == this.displayedBandsInfo.FirstDisplayedScrollingRow))
                 {
                     this.AutoResizeRowInternal(nextRow, MapAutoSizeRowsModeToRowMode(autoSizeRowsMode), fixedWidth, internalAutosizing);
                     num3 += this.Rows.SharedRow(nextRow).GetHeight(nextRow);
                     nextRow = this.Rows.GetNextRow(nextRow, DataGridViewElementStates.Visible);
                 }
                 do
                 {
                     firstDisplayedScrollingRow = this.displayedBandsInfo.FirstDisplayedScrollingRow;
                     if (num3 < height)
                     {
                         int rowIndex = this.Rows.GetPreviousRow(this.displayedBandsInfo.FirstDisplayedScrollingRow, DataGridViewElementStates.Visible, DataGridViewElementStates.Frozen);
                         if (rowIndex != -1)
                         {
                             this.AutoResizeRowInternal(rowIndex, MapAutoSizeRowsModeToRowMode(autoSizeRowsMode), fixedWidth, internalAutosizing);
                         }
                     }
                     num3 = num5;
                     for (nextRow = this.displayedBandsInfo.FirstDisplayedScrollingRow; (nextRow != -1) && (num3 < height); nextRow = this.Rows.GetNextRow(nextRow, DataGridViewElementStates.Visible))
                     {
                         this.AutoResizeRowInternal(nextRow, MapAutoSizeRowsModeToRowMode(autoSizeRowsMode), fixedWidth, internalAutosizing);
                         num3 += this.Rows.SharedRow(nextRow).GetHeight(nextRow);
                     }
                 }
                 while (firstDisplayedScrollingRow != this.displayedBandsInfo.FirstDisplayedScrollingRow);
             }
         }
         finally
         {
             this.ExitBulkPaint(-1, -1);
         }
     }
 }
 public void AutoResizeRows(DataGridViewAutoSizeRowsMode autoSizeRowsMode);
 protected void AutoResizeRows(DataGridViewAutoSizeRowsMode autoSizeRowsMode, bool fixedWidth);
Exemple #13
0
 public void AutoResizeRows(DataGridViewAutoSizeRowsMode autoSizeRowsMode)
 {
 }
 protected void AutoResizeRows(DataGridViewAutoSizeRowsMode autoSizeRowsMode, bool fixedWidth)
 {
     switch (autoSizeRowsMode)
     {
         case DataGridViewAutoSizeRowsMode.None:
         case DataGridViewAutoSizeRowsMode.AllHeaders:
         case DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders:
         case DataGridViewAutoSizeRowsMode.AllCells:
         case DataGridViewAutoSizeRowsMode.DisplayedHeaders:
         case DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders:
         case DataGridViewAutoSizeRowsMode.DisplayedCells:
             if (autoSizeRowsMode == DataGridViewAutoSizeRowsMode.None)
             {
                 throw new ArgumentException(System.Windows.Forms.SR.GetString("DataGridView_NeedAutoSizingCriteria", new object[] { "autoSizeRowsMode" }));
             }
             if (((autoSizeRowsMode == DataGridViewAutoSizeRowsMode.AllHeaders) || (autoSizeRowsMode == DataGridViewAutoSizeRowsMode.DisplayedHeaders)) && !this.RowHeadersVisible)
             {
                 throw new InvalidOperationException(System.Windows.Forms.SR.GetString("DataGridView_CannotAutoSizeRowsInvisibleRowHeader"));
             }
             this.AdjustShrinkingRows(autoSizeRowsMode, fixedWidth, false);
             return;
     }
     throw new InvalidEnumArgumentException("value", (int) autoSizeRowsMode, typeof(DataGridViewAutoSizeRowsMode));
 }
 public void AutoResizeRows(DataGridViewAutoSizeRowsMode autoSizeRowsMode)
 {
     this.AutoResizeRows(autoSizeRowsMode, true);
 }
Exemple #16
0
		protected void AutoResizeRows (DataGridViewAutoSizeRowsMode autoSizeRowsMode, bool fixedWidth)
		{
			if (autoSizeRowsMode == DataGridViewAutoSizeRowsMode.None)
				return;
				
			bool displayed_only = false;
			DataGridViewAutoSizeRowMode mode = DataGridViewAutoSizeRowMode.AllCells;
			
			switch (autoSizeRowsMode) {
				case DataGridViewAutoSizeRowsMode.AllHeaders:
					mode = DataGridViewAutoSizeRowMode.RowHeader;
					break;
				case DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders:
					mode = DataGridViewAutoSizeRowMode.AllCellsExceptHeader;
					break;
				case DataGridViewAutoSizeRowsMode.AllCells:
					mode = DataGridViewAutoSizeRowMode.AllCells;
					break;
				case DataGridViewAutoSizeRowsMode.DisplayedHeaders:
					mode = DataGridViewAutoSizeRowMode.RowHeader;
					displayed_only = true;
					break;
				case DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders:
					mode = DataGridViewAutoSizeRowMode.AllCellsExceptHeader;
					displayed_only = true;
					break;
				case DataGridViewAutoSizeRowsMode.DisplayedCells:
					mode = DataGridViewAutoSizeRowMode.AllCells;
					displayed_only = true;
					break;
			}
			
			foreach (DataGridViewRow row in Rows) {
				if (!row.Visible)
					continue;
				if (!displayed_only || row.Displayed) {
					int new_height = row.GetPreferredHeight (row.Index, mode, fixedWidth);

					if (row.Height != new_height)
						row.SetAutoSizeHeight (new_height);
				}
			}
		}
        private static DataGridViewAutoSizeRowMode MapAutoSizeRowsModeToRowMode(DataGridViewAutoSizeRowsMode autoSizeRowsMode)
        {
            switch (autoSizeRowsMode)
            {
                case DataGridViewAutoSizeRowsMode.AllHeaders:
                    return DataGridViewAutoSizeRowMode.RowHeader;

                case DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders:
                    return DataGridViewAutoSizeRowMode.AllCellsExceptHeader;

                case DataGridViewAutoSizeRowsMode.AllCells:
                    return DataGridViewAutoSizeRowMode.AllCells;

                case DataGridViewAutoSizeRowsMode.DisplayedHeaders:
                    return DataGridViewAutoSizeRowMode.RowHeader;

                case DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders:
                    return DataGridViewAutoSizeRowMode.AllCellsExceptHeader;

                case DataGridViewAutoSizeRowsMode.DisplayedCells:
                    return DataGridViewAutoSizeRowMode.AllCells;
            }
            return DataGridViewAutoSizeRowMode.RowHeader;
        }
        /// <summary>
        ///   Sets the auto-size mode for the rows.
        /// </summary>
        /// 
        public DataGridBox SetAutoSizeRows(DataGridViewAutoSizeRowsMode mode)
        {
            if (this.InvokeRequired)
            {
                this.Invoke((Action)(() => SetAutoSizeRows(mode)));
                return this;
            }

            dataGridView.AutoSizeRowsMode = mode;

            return this;
        }
 public DataGridView()
 {
     base.SetStyle(ControlStyles.UserMouse | ControlStyles.Opaque | ControlStyles.UserPaint, true);
     base.SetStyle(ControlStyles.SupportsTransparentBackColor, false);
     base.SetState2(0x800, true);
     this.dataGridViewState1 = new BitVector32(0);
     this.dataGridViewState2 = new BitVector32(0);
     this.dataGridViewOper = new BitVector32(0);
     this.dataGridViewState1[0x80001b] = true;
     this.dataGridViewState2[0x60003e7] = true;
     this.displayedBandsInfo = new DisplayedBandsData();
     this.lstRows = new ArrayList();
     this.converters = new Hashtable(8);
     this.pens = new Hashtable(8);
     this.brushes = new Hashtable(10);
     this.gridPen = new Pen(DefaultGridColor);
     this.selectedBandIndexes = new DataGridViewIntLinkedList();
     this.individualSelectedCells = new DataGridViewCellLinkedList();
     this.individualReadOnlyCells = new DataGridViewCellLinkedList();
     this.advancedCellBorderStyle = new DataGridViewAdvancedBorderStyle(this, DataGridViewAdvancedCellBorderStyle.OutsetDouble, DataGridViewAdvancedCellBorderStyle.OutsetPartial, DataGridViewAdvancedCellBorderStyle.InsetDouble);
     this.advancedRowHeadersBorderStyle = new DataGridViewAdvancedBorderStyle(this);
     this.advancedColumnHeadersBorderStyle = new DataGridViewAdvancedBorderStyle(this);
     this.advancedCellBorderStyle.All = DataGridViewAdvancedCellBorderStyle.Single;
     this.advancedRowHeadersBorderStyle.All = DataGridViewAdvancedCellBorderStyle.OutsetPartial;
     this.advancedColumnHeadersBorderStyle.All = DataGridViewAdvancedCellBorderStyle.OutsetPartial;
     this.borderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
     this.dataGridViewState1[0x80] = true;
     this.selectionMode = DataGridViewSelectionMode.RowHeaderSelect;
     this.editMode = DataGridViewEditMode.EditOnKeystrokeOrF2;
     this.autoSizeRowsMode = DataGridViewAutoSizeRowsMode.None;
     this.autoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
     this.columnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing;
     this.rowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.EnableResizing;
     this.clipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithAutoHeaderText;
     this.layout = new LayoutData();
     this.layout.TopLeftHeader = Rectangle.Empty;
     this.layout.ColumnHeaders = Rectangle.Empty;
     this.layout.RowHeaders = Rectangle.Empty;
     this.layout.ColumnHeadersVisible = true;
     this.layout.RowHeadersVisible = true;
     this.layout.ClientRectangle = base.ClientRectangle;
     this.scrollBars = System.Windows.Forms.ScrollBars.Both;
     this.horizScrollBar.RightToLeft = RightToLeft.Inherit;
     this.horizScrollBar.AccessibleName = System.Windows.Forms.SR.GetString("DataGridView_AccHorizontalScrollBarAccName");
     this.horizScrollBar.Top = base.ClientRectangle.Height - this.horizScrollBar.Height;
     this.horizScrollBar.Left = 0;
     this.horizScrollBar.Visible = false;
     this.horizScrollBar.Scroll += new ScrollEventHandler(this.DataGridViewHScrolled);
     base.Controls.Add(this.horizScrollBar);
     this.vertScrollBar.Top = 0;
     this.vertScrollBar.AccessibleName = System.Windows.Forms.SR.GetString("DataGridView_AccVerticalScrollBarAccName");
     this.vertScrollBar.Left = base.ClientRectangle.Width - this.vertScrollBar.Width;
     this.vertScrollBar.Visible = false;
     this.vertScrollBar.Scroll += new ScrollEventHandler(this.DataGridViewVScrolled);
     base.Controls.Add(this.vertScrollBar);
     this.ptCurrentCell = new Point(-1, -1);
     this.ptAnchorCell = new Point(-1, -1);
     this.ptMouseDownCell = new Point(-2, -2);
     this.ptMouseEnteredCell = new Point(-2, -2);
     this.ptToolTipCell = new Point(-1, -1);
     this.ptMouseDownGridCoord = new Point(-1, -1);
     this.sortOrder = System.Windows.Forms.SortOrder.None;
     this.lastMouseClickInfo.timeStamp = 0L;
     this.WireScrollBarsEvents();
     base.PerformLayout();
     this.toolTipControl = new DataGridViewToolTip(this);
     base.Invalidate();
 }
Exemple #20
0
        public static DataGridView GetDataGridView(DataGridViewSelectionMode selectionMode, DataGridViewAutoSizeRowsMode rowsSizeMode, bool createSaveMenu = false)
        {
            DataGridView grid = new DataGridView();

            grid.AllowUserToOrderColumns     = true;
            grid.AllowUserToResizeRows       = true;
            grid.AutoSizeRowsMode            = rowsSizeMode;
            grid.AllowUserToDeleteRows       = false;
            grid.AllowUserToAddRows          = false;
            grid.RowHeadersVisible           = false;
            grid.SelectionMode               = selectionMode;
            grid.MultiSelect                 = false;
            grid.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            grid.ScrollBars      = ScrollBars.None;
            grid.BackColor       = Color.FromArgb(21, 26, 30);
            grid.BackgroundColor = Color.FromArgb(21, 26, 30);

            grid.GridColor = Color.FromArgb(17, 18, 23);
            grid.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.None;
            grid.BorderStyle = BorderStyle.None;
            DataGridViewCellStyle style = new DataGridViewCellStyle();

            style.Alignment          = DataGridViewContentAlignment.TopLeft;
            style.WrapMode           = DataGridViewTriState.True;
            style.BackColor          = Color.FromArgb(21, 26, 30);
            style.SelectionBackColor = Color.FromArgb(17, 18, 23);
            style.ForeColor          = Color.FromArgb(154, 156, 158);

            grid.DefaultCellStyle = style;
            grid.ColumnHeadersDefaultCellStyle = style;

            grid.MouseHover += delegate(object sender, EventArgs args)
            {
                grid.Focus();
            };

            grid.MouseLeave += delegate(object sender, EventArgs args)
            {
                grid.EndEdit();
            };

            grid.MouseWheel += delegate(object sender, MouseEventArgs args)
            {
                if (grid.SelectedCells.Count == 0)
                {
                    return;
                }
                int rowInd = grid.SelectedCells[0].RowIndex;
                if (args.Delta < 0)
                {
                    rowInd++;
                }
                else if (args.Delta > 0)
                {
                    rowInd--;
                }

                if (rowInd < 0)
                {
                    rowInd = 0;
                }

                if (rowInd >= grid.Rows.Count)
                {
                    rowInd = grid.Rows.Count - 1;
                }

                grid.Rows[rowInd].Selected = true;
                grid.Rows[rowInd].Cells[grid.SelectedCells[0].ColumnIndex].Selected = true;

                if (grid.FirstDisplayedScrollingRowIndex > rowInd)
                {
                    grid.FirstDisplayedScrollingRowIndex = rowInd;
                }
            };

            if (createSaveMenu)
            {
                List <MenuItem> items = new List <MenuItem>();

                items.Add(new MenuItem("Save table in file"));

                items[items.Count - 1].Click += delegate(Object sender, EventArgs e)
                {
                    if (grid.Rows.Count == 0)
                    {
                        return;
                    }

                    try
                    {
                        SaveFileDialog myDialog = new SaveFileDialog();
                        myDialog.Filter = "*.txt|";
                        myDialog.ShowDialog();

                        if (string.IsNullOrEmpty(myDialog.FileName))
                        {
                            MessageBox.Show(OsLocalization.Journal.Message1);
                            return;
                        }

                        string fileName = myDialog.FileName;
                        if (fileName.Split('.').Length == 1)
                        {
                            fileName = fileName + ".txt";
                        }

                        string saveStr = "";

                        for (int i = 0; i < grid.Columns.Count; i++)
                        {
                            saveStr += grid.Columns[i].HeaderText + ",";
                        }

                        saveStr += "\r\n";

                        for (int i = 0; i < grid.Rows.Count; i++)
                        {
                            saveStr += grid.Rows[i].ToFormatString() + "\r\n";
                        }


                        StreamWriter writer = new StreamWriter(fileName);
                        writer.Write(saveStr);
                        writer.Close();
                    }
                    catch (Exception error)
                    {
                        MessageBox.Show(error.ToString());
                    }
                };

                ContextMenu menu = new ContextMenu(items.ToArray());
                grid.ContextMenu = menu;

                grid.Click += delegate(Object sender, EventArgs e)
                {
                    MouseEventArgs mouse = (MouseEventArgs)e;
                    if (mouse.Button != MouseButtons.Right)
                    {
                        return;
                    }

                    grid.ContextMenu = menu;
                    grid.ContextMenu.Show(grid, new Point(mouse.X, mouse.Y));
                };
            }

            return(grid);
        }
 private static DataGridViewAutoSizeRowMode MapAutoSizeRowsModeToRowMode(DataGridViewAutoSizeRowsMode autoSizeRowsMode)
 {
     switch (autoSizeRowsMode)
     {
         case DataGridViewAutoSizeRowsMode.AllHeaders:
             return DataGridViewAutoSizeRowMode.RowHeader;
         case DataGridViewAutoSizeRowsMode.DisplayedHeaders:
             return DataGridViewAutoSizeRowMode.RowHeader;
         case DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders:
             return DataGridViewAutoSizeRowMode.AllCellsExceptHeader;
         case DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders:
             return DataGridViewAutoSizeRowMode.AllCellsExceptHeader;
         case DataGridViewAutoSizeRowsMode.AllCells:
             return DataGridViewAutoSizeRowMode.AllCells;
         case DataGridViewAutoSizeRowsMode.DisplayedCells:
             return DataGridViewAutoSizeRowMode.AllCells;
         default:
             Debug.Fail("Unexpected autoSizeRowsMode value in MapAutoSizeRowsModeToRowMode");
             return DataGridViewAutoSizeRowMode.RowHeader;
     }
 }