예제 #1
0
        /// <summary>
        ///  列表头添加 全选CheckBox
        /// </summary>
        void BindAllSelectEvent()
        {
            DataGridViewCheckBoxColumn dbCbo = new DataGridViewCheckBoxColumn();

            this.DataGridViewExControl.Columns.Insert(CheckBoxExColumnIndex, dbCbo);
            this.DataGridViewExControl.DataBindingComplete += new DataGridViewBindingCompleteEventHandler(DataGridViewExControl_DataBindingComplete);
            this.DataGridViewExControl.Scroll += new ScrollEventHandler(DataGridViewExCheckBox_Scroll);
            System.Windows.Forms.CheckBox ckBox = new System.Windows.Forms.CheckBox();
            System.Drawing.Rectangle      rect  = DataGridViewExControl.GetCellDisplayRectangle(CheckBoxExColumnIndex, -1, true);
            ckBox.Name            = "ck";
            ckBox.Size            = new System.Drawing.Size(13, 13);
            ckBox.Location        = new Point(6 + rect.Location.X + DataGridViewExControl.Columns[CheckBoxExColumnIndex].Width / 2 - 13 / 2, rect.Location.Y + 3);
            ckBox.CheckedChanged += new EventHandler(DataGridViewExCheckBox_CheckedChanged);
            this.DataGridViewExControl.Controls.Add(ckBox);
            this.DataGridViewExControl.Columns[CheckBoxExColumnIndex].Width = 30;
        }
예제 #2
0
        // Показывает на экране элемент для ввода даты и времени
        public static void EnterDateTimeCell(DataGridView dataGridView, DataGridViewCellEventArgs e, DateTimePickerFormat dateTimePickerFormat)
        {
            if (dataGridView.Columns[e.ColumnIndex].ValueType == typeof(DateTime))
            {
                CreateDateTimePicker();

                currentDataGridView = dataGridView;
                dtpEventDatePicker.Tag = e;

                //dtpEventDatePicker.TextChanged += new EventHandler(dtpEventDatePicker_TextChanged);

                if (dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value is DateTime)
                    dtpEventDatePicker.Value = (DateTime)dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
                else
                    dtpEventDatePicker.Value = DateTime.Today;

                dtpEventDatePicker.Format = dateTimePickerFormat;

                if (dtpEventDatePicker.Format == DateTimePickerFormat.Time)
                    dtpEventDatePicker.ShowUpDown = true;
                else
                    dtpEventDatePicker.ShowUpDown = false;

                dtpEventDatePicker.Parent = dataGridView;
                dtpEventDatePicker.Bounds = dataGridView.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false);

                dtpEventDatePicker.Visible = !dataGridView.ReadOnly;

            }
        }
예제 #3
0
        public DialogResult setVisibility(DataGridView EditedDataGridView)
        {
            try
            {

                System.Drawing.Rectangle CellRectangle1 = EditedDataGridView.GetCellDisplayRectangle(2, 2, true);

                this.Location = EditedDataGridView.PointToClient(new Point(EditedDataGridView.Left +  2 * EditedDataGridView.RowHeadersWidth, EditedDataGridView.Top + 2 * EditedDataGridView.ColumnHeadersHeight));

                foreach (DataGridViewColumn CurrentColumn in EditedDataGridView.Columns)
                {
                    dgvColumns.Rows.Add(CurrentColumn.Name,
                                        CurrentColumn.HeaderText,
                                        CurrentColumn.DisplayIndex.ToString(),
                                        CurrentColumn.Visible,
                                        CurrentColumn.AutoSizeMode.ToString(),
                                        CurrentColumn.Width.ToString(),
                                        CurrentColumn.FillWeight.ToString(),
                                        CurrentColumn.MinimumWidth.ToString());
                }

                this.ShowDialog(EditedDataGridView);

                if(this.DialogResult == System.Windows.Forms.DialogResult.OK)
                {
                    Int32 ColumnIndex=0;

                    foreach (DataGridViewColumn CurrentColumn in EditedDataGridView.Columns)
                    {
                        CurrentColumn.DisplayIndex   = Int32.Parse(dgvColumns.Rows[ColumnIndex].Cells["colDisplayIndex"].Value.ToString());
                        CurrentColumn.Visible        = (Boolean)dgvColumns.Rows[ColumnIndex].Cells["colVisible"].Value;
                        CurrentColumn.AutoSizeMode   = (DataGridViewAutoSizeColumnMode)Enum.Parse(typeof(DataGridViewAutoSizeColumnMode), (String)dgvColumns.Rows[ColumnIndex].Cells["colAutoSizeMode"].Value);

                        if(CurrentColumn.AutoSizeMode == DataGridViewAutoSizeColumnMode.Fill)
                            CurrentColumn.FillWeight     = Single.Parse(dgvColumns.Rows[ColumnIndex].Cells["colFillWeight"].Value.ToString().Replace(",", "."),System.Globalization.NumberStyles.AllowDecimalPoint,System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
                        else
                            CurrentColumn.Width          = Int32.Parse(dgvColumns.Rows[ColumnIndex].Cells["colWidth"].Value.ToString());

                        CurrentColumn.MinimumWidth   = Int32.Parse(dgvColumns.Rows[ColumnIndex].Cells["colMinimumWidth"].Value.ToString());

                        ColumnIndex++;

                    }
                }

                return DialogResult;
            }
            catch (Exception ex)
            {
                throw new Exception("Error while editing column visibility", ex);
            }
        }
예제 #4
0
 private static void DrawCkBox(System.Windows.Forms.DataGridView dgv)
 {
     System.Windows.Forms.CheckBox ckBox = new System.Windows.Forms.CheckBox();
     System.Drawing.Point          p     = dgv.GetCellDisplayRectangle(0, -1, true).Location;
     ckBox.Size = new System.Drawing.Size(18, 18);
     p.Offset(((dgv.Columns[0].Width - ckBox.Width) / 2) + 4, 2);
     ckBox.Location = p;
     ckBox.Visible  = true;
     ckBox.BringToFront();
     ckBox.BackColor       = System.Drawing.Color.White;
     ckBox.ThreeState      = false;
     ckBox.Checked         = false;
     ckBox.CheckedChanged += new EventHandler(ckBox_CheckedChanged);
     dgv.Controls.Add(ckBox);
 }
예제 #5
0
        public static void AddFullSelect()
        {
            var cbCol = new DataGridViewCheckBoxColumn();

            cbCol.Width      = 50;
            cbCol.HeaderText = "";
            cbCol.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            cbCol.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
            cbCol.ReadOnly     = false;
            dgv.Columns.Insert(0, cbCol);

            var rect     = dgv.GetCellDisplayRectangle(0, -1, true);
            var checkBox = new System.Windows.Forms.CheckBox();

            checkBox.Name            = "SelectAllCheckBox";
            checkBox.Size            = new System.Drawing.Size(13, 13);
            checkBox.Location        = new System.Drawing.Point(rect.Location.X + dgv.Columns[0].Width / 2 - 13 / 2 - 1, rect.Location.Y + 3);
            checkBox.CheckedChanged += new EventHandler(ckBox_CheckedChanged);
            dgv.Controls.Add(checkBox);
        }
예제 #6
0
        void dataGrid1_Paint(object sender, PaintEventArgs e)
        {
            if (dataGridView1.DataSource != null)
            {
                for (int i = 1; i <= 15; i++)
                {
                    Rectangle rect = dataGridView1.GetCellDisplayRectangle(0, i - 1, true);
                    if (i > 9)
                    {
                        rect.X = rect.X - 28;
                    }
                    else
                    {
                        rect.X = rect.X - 24;
                    }

                    e.Graphics.DrawString(i.ToString(), new Font("Verdana", 9f, FontStyle.Regular), Brushes.Black, rect);
                }
            }
        }
예제 #7
0
 /// <summary>  
 /// DataGridView添加全选  
 /// </summary>  
 /// <param name="dgv">DataGridView控件ID</param>  
 /// <param name="columnIndex">全选所在列序号</param>  
 public void AddFullSelect(DataGridView dgv, int columnIndex)
 {
     if (dgv.Rows.Count < 1)
     {
         return;
     }
     CheckBox ckBox = new CheckBox();
     Rectangle rect = dgv.GetCellDisplayRectangle(1, -1, true);
     ckBox.Size = new Size(dgv.Columns[1].Width - 12, 12); //大小
     Point point = new Point(rect.X + 10, rect.Y + 3);//位置
     ckBox.Location = point;
     ckBox.CheckedChanged += delegate(object sender, EventArgs e)
     {
         for (int i = 0; i < dgv.Rows.Count; i++)
         {
             dgv.Rows[i].Cells[columnIndex].Value = ((CheckBox)sender).Checked;
         }
         dgv.EndEdit();
     };
     dgv.Controls.Add(ckBox);
 }
예제 #8
0
        public static void EnterDateTimeCell(DataGridView dataGridView, DataGridViewCellEventArgs e, string customFromat)
        {
            if (dataGridView.Columns[e.ColumnIndex].ValueType == typeof(DateTime))
            {
                CreateDateTimePicker();

                currentDataGridView = dataGridView;
                dtpEventDatePicker.Tag = e;

                if (dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value is DateTime)
                    dtpEventDatePicker.Value = (DateTime)dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
                else
                    dtpEventDatePicker.Value = DateTime.Today;

                dtpEventDatePicker.Format = DateTimePickerFormat.Custom;
                dtpEventDatePicker.CustomFormat = customFromat;
                dtpEventDatePicker.Parent = dataGridView;
                dtpEventDatePicker.Bounds = dataGridView.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false);
                dtpEventDatePicker.ShowUpDown = true;
                dtpEventDatePicker.Visible = true;

            }
        }
예제 #9
0
        private void drawGridOnPdfdocument(DataGridView displayGrid, XGraphics gfx, int displayXOffset, int displayYOffset)
        {
            XColor back = XColors.Transparent;
            back.A = 0.1;
            XSolidBrush BorderBrush = new XSolidBrush(back);
            XPen pen = new XPen(XColors.Gray, 1);
            //Side Panels
            double height = displayGrid.Height + 5;
            double width = displayGrid.Width + 7;
            gfx.DrawRoundedRectangle(pen, BorderBrush, displayGrid.Location.X - 8, displayGrid.Location.Y - 20 + displayYOffset, width, height, 10, 10);
            gfx.DrawRoundedRectangle(pen, BorderBrush, displayGrid.Location.X - 5, displayGrid.Location.Y + 365, 1058, 28, 5, 5);
            XFont headerfont = new XFont("Aerial", 13, XFontStyle.Bold);
            XTextFormatter tf = new XTextFormatter(gfx);
            XPen newPen = new XPen(Color.Black);
            XColor fillColor = XColors.DarkOrange;
            XBrush brush = new XSolidBrush(fillColor);
            fillColor.A = 0.8;

            int headerOffset = 0;
            foreach (DataGridViewColumn colmn in displayGrid.Columns)
            {
                if (colmn.Visible)
                {
                    Rectangle header_rect = displayGrid.GetCellDisplayRectangle(colmn.Index, -1, false);
                    XRect pdf_rect = new XRect(header_rect.X + displayXOffset, header_rect.Y + displayYOffset, header_rect.Width, header_rect.Height);
                    headerOffset = header_rect.Height;
                    gfx.DrawRectangle(newPen, pdf_rect);
                    tf.Alignment = XParagraphAlignment.Center;
                    tf.DrawString(colmn.HeaderText, headerfont, XBrushes.Black, pdf_rect, XStringFormats.TopLeft);
                }

            }

            XFont font = new XFont("Aerial", 13, XFontStyle.Bold);
            foreach (DataGridViewRow dgRow in displayGrid.Rows)
                foreach (DataGridViewColumn dgCol in displayGrid.Columns)
                {
                    if (dgCol.Visible)
                    {
                        Rectangle rect = displayGrid.GetCellDisplayRectangle(dgCol.Index, dgRow.Index, true);
                        XRect pdf_rect = new XRect(rect.X + displayXOffset, rect.Y + displayYOffset, rect.Width, rect.Height);
                        gfx.DrawRectangle(newPen, pdf_rect);
                        tf.Alignment = XParagraphAlignment.Center;
                        string displayText = getCellFormatedValue(displayGrid.Rows[dgRow.Index].Cells[dgCol.Index]);
                        tf.DrawString(displayText, headerfont, XBrushes.Black, pdf_rect, XStringFormats.TopLeft);
                    }

                }
        }
예제 #10
0
        private void UI_MergeColumns(DataGridView grid, int col, uint num, Graphics g)
        {
            for(int i=0; i < num; i++)
            {
                if (col + i >= grid.Columns.Count) break;

                DataGridViewCell hc = grid.Columns[col + i].HeaderCell;
                Rectangle hcRct = grid.GetCellDisplayRectangle(hc.ColumnIndex, -1, true);

                Rectangle left = new Rectangle(hcRct.Left, hcRct.Top + 2, 1, hcRct.Height - 4);
                Rectangle right = new Rectangle(hcRct.Left+hcRct.Width-1, hcRct.Top + 2, 1, hcRct.Height - 4);

                using (var brush = new SolidBrush(grid.Columns[col + i].HeaderCell.Style.BackColor))
                {
                    if (i != 0)
                        g.FillRectangle(brush, left);
                    if (i != num - 1)
                        g.FillRectangle(brush, right);
                }
            }
        }
예제 #11
0
        void dgv_CellClick1(object sender, DataGridViewCellEventArgs e,string[] ColumnsName)
        {
            dgv = (DataGridView)sender;
            if (ColumnsName.Contains(dgv.Columns[e.ColumnIndex].Name))
            {
                foreach (Control c in dgv.Controls)
                    dgv.Controls.Remove(c);
                //Initialized a new DateTimePicker Control
                oDateTimePicker = new DateTimePicker();

                //Adding DateTimePicker control into DataGridView
                dgv.Controls.Add(oDateTimePicker);

                // Setting the format (i.e. 2014-10-10)
                oDateTimePicker.Format = DateTimePickerFormat.Short;

                // It returns the retangular area that represents the Display area for a cell
                Rectangle oRectangle = dgv.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true);

                //Setting area for DateTimePicker Control
                oDateTimePicker.Size = new Size(oRectangle.Width, oRectangle.Height);

                // Setting Location
                oDateTimePicker.Location = new Point(oRectangle.X, oRectangle.Y);

                if (dgv.CurrentCell.Value != DBNull.Value && dgv.CurrentCell.Value != null)
                    oDateTimePicker.Value = Convert.ToDateTime(dgv.CurrentCell.Value);

                // An event attached to dateTimePicker Control which is fired when DateTimeControl is closed
                oDateTimePicker.CloseUp += new EventHandler(oDateTimePicker_CloseUp);

                // An event attached to dateTimePicker Control which is fired when any date is selected
                oDateTimePicker.TextChanged += new EventHandler(dateTimePicker_OnTextChange);

                // Now make it visible
                oDateTimePicker.Visible = true;
            }
            else
            {
                HiddenDateTimePicker();
            }
        }
예제 #12
0
파일: MainForm.cs 프로젝트: yeegahng/CLV
		private void ShowCellInfoIfPossible(DataGridView view, int rowIndex, int columnIndex, int popupDuration = 0)
		{
			if(rowIndex >= 0 && columnIndex >= 0)
			{				
				//RowIndex=>LogLinePairIndex, ColumnIndex-2=>DataFieldIndex (due to Line#, MsgName)
				if(LogLinePairList[rowIndex].TranslatedLogLine.Count >= columnIndex
				   && 0 < (columnIndex-1))
				{
					DataField dataField = (DataField)(LogLinePairList[rowIndex].TranslatedLogLine[columnIndex-1]);
					String content = dataField.FieldName;
					Rectangle viewRect = view.GetCellDisplayRectangle(columnIndex, rowIndex, true);
					Point viewLocation = view.Location;					
					Debug.Log("ToolTip: " + content + " at viewRect=" + viewRect);
					ShowInfoPopup(viewRect.Left, viewRect.Top, content, popupDuration);
				}
		    }
		}
 public void ShowSearch(DataGridView parentGrid, int _ColumnIndex, int _RowIndex,Popup _popup)
 {
     _DgView = parentGrid;
     _CurrentColumnIndex = _ColumnIndex;
     Rectangle Rect = _DgView.GetCellDisplayRectangle(_ColumnIndex, _RowIndex, false);
     Rectangle RectToDiplay = new Rectangle(Rect.X, Rect.Y - this.ClientRectangle.Height, this.ClientRectangle.Width, this.ClientRectangle.Height);
     _popup.Show(_DgView, RectToDiplay);
 }
예제 #14
0
        //public void ShowSearch(DataGridView parentGrid, int _ColumnIndex, int _RowIndex,Popup _popup)
        //{
        //    _DgView = parentGrid;
        //    _CurrentColumnIndex = _ColumnIndex;
        //    Rectangle Rect = _DgView.GetCellDisplayRectangle(_ColumnIndex, _RowIndex,false );
        //    Rectangle RectToDiplay = new Rectangle(Rect.X, Rect.Y - this.ClientRectangle.Height, this.ClientRectangle.Width, this.ClientRectangle.Height);
        //    //if (RectToDiplay.X < 0)
        //    //    RectToDiplay.X = 0;
        //    //if (RectToDiplay.Y < 0)
        //    //    RectToDiplay.Y = 0;
        //    _popup.Show(_DgView, RectToDiplay);
        //}
        public void ShowSearch(DataGridView parentGrid, int _ColumnIndex, int _RowIndex, Popup _popup,bool OpenOnRight)
        {
            _DgView = parentGrid;
            _CurrentColumnIndex = _ColumnIndex;
            Rectangle Rect = _DgView.GetCellDisplayRectangle(_ColumnIndex, _RowIndex, false);
            //if (OpenOnRight)
            //{
            //    Rectangle RectToDiplay = new Rectangle(Rect.Right - this.ClientRectangle.Width, Rect.Y - this.ClientRectangle.Height, this.ClientRectangle.Width, this.ClientRectangle.Height);
            //    _popup.Show(_DgView, RectToDiplay);

            //}
            //else
            //{

                Rectangle RectToDiplay = new Rectangle(Rect.X, Rect.Y - this.ClientRectangle.Height, this.ClientRectangle.Width, this.ClientRectangle.Height);
                _popup.Show(_DgView, RectToDiplay);
            //}
        }