void Init () { AutoGenerateColumns = false; MouseDown += new System.Windows.Forms.MouseEventHandler ( this.OnMouseDown ); CellDoubleClick += new System.Windows.Forms.DataGridViewCellEventHandler ( this.OnCellDBClick ); CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler ( this.OnCellContentClick ); CellClick += new System.Windows.Forms.DataGridViewCellEventHandler ( this.OnCellClick ); ColumnHeaderMouseClick += new DataGridViewCellMouseEventHandler ( OnClickColumnHeader ); //作废。列表排序不在这里实现。而是在 FindList 类中,通过 fl.SortBindingList() 来实现。DataGridView类自身自带了排序功能,只需要传入有排序属性的数据就可以了。 CellFormatting += new DataGridViewCellFormattingEventHandler(OnCellFormatting); //在显示数据的同时,对Cell里的数据/颜色/字体等进行处理。不必再使用AfterFill()之类的函数了。 ClearContextMenu () ; //ListViewColumnSorter sortHelper = new ListViewColumnSorter(); //Sort( sortHelper ); }
public DataGridViewAdmin(Color foreColor, Color [] backgroundColors) : base(foreColor, backgroundColors, false) { //Thread.CurrentThread.SetApartmentState(ApartmentState.STA); InitializeComponents(); CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgwAdminTable_CellClick); CellValidated += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgwAdminTable_CellValidated); Name = "m_dgwAdminTable"; RowHeadersVisible = false; RowTemplate.Resizable = DataGridViewTriState.False; RowsAdd(); this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.dgwAdminTable_KeyUp); }
void InitCtrol () { ReadOnly = true; //this.AllowAddRows = false; AllowUserToAddRows = false; AllowUserToDeleteRows = false; AllowUserToResizeRows = false; ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; MultiSelect = false; RowHeadersVisible = false; SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; ScrollBars = System.Windows.Forms.ScrollBars.Both; BackgroundColor = System.Drawing.Color.White; BorderStyle = System.Windows.Forms.BorderStyle.None; Scroll += new System.Windows.Forms.ScrollEventHandler(OnScroll); CellDoubleClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.OnCellDoubleClick); txtBox.KeyDown += new KeyEventHandler ( OnKeyDown ); RowTemplate.Height = _nLineH; SetStyle(ControlStyles.DoubleBuffer | ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true); UpdateStyles(); // Columns.Clear(); DataGridViewColumn col1 = new DataGridViewTextBoxColumn (); col1.HeaderText = "Caption"; col1.Name = "Caption"; col1.DataPropertyName = "Caption"; col1.ReadOnly = true; Columns.Add ( col1 ); DataGridViewColumn col2 = new DataGridViewTextBoxColumn (); col2.HeaderText = "Value"; col2.Name = "Value"; col2.DataPropertyName = "Value"; col2.ReadOnly = false; Columns.Add ( col2 ); DataGridViewColumn col3 = new DataGridViewTextBoxColumn (); col3.HeaderText = "Def"; col3.Name = "Def"; col3.DataPropertyName = "Def"; col3.ReadOnly = true; col3.Visible = false; Columns.Add ( col3 ); Columns[0].DefaultCellStyle.ForeColor = clrCaptionFore; Columns[0].DefaultCellStyle.BackColor = clrCaptionBK; // txtBox.Parent = this; txtBox.AcceptsReturn = true; txtBox.WordWrap = false; txtBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler ( textBoxKeyPress ); txtBox.Hide(); cmb.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; cmb.SelectedIndexChanged += new System.EventHandler ( cmb_SelectedIndexChanged ); cmb.Parent = this; cmb.Hide(); datPicker.Parent = this; datPicker.bShowTime = true; datPicker.Finish += dateTimePicker_ValueChanged ; datPicker.Hide(); }
public StyledDataGridView() { //if (!DesignMode) LP.Validate(); showGridBorder = true; HeightOfRealAndNewRows = -1; RowDividerIndex = new System.Collections.Generic.List <int>(); _CustomEnabled = true; _CustomActive = true; _EditOnSingleClick = true; SuspendLayout(); AllowUserToResizeRows = false; RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.DisableResizing; AutoSizeRowsMode = System.Windows.Forms.DataGridViewAutoSizeRowsMode.DisplayedCells; System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); dataGridViewCellStyle1.BackColor = System.Drawing.Color.FromArgb(228, 241, 249); dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight; dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText; AlternatingRowsDefaultCellStyle = dataGridViewCellStyle1; DefaultCellStyle.SelectionBackColor = System.Drawing.SystemColors.Highlight; DefaultCellStyle.SelectionForeColor = System.Drawing.SystemColors.HighlightText; CellBorderStyle = System.Windows.Forms.DataGridViewCellBorderStyle.None; AutoGenerateColumns = false; BackgroundColor = System.Drawing.Color.FromArgb(200, 226, 243); BorderStyle = System.Windows.Forms.BorderStyle.None; ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.Single; System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle(); dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; dataGridViewCellStyle2.BackColor = System.Drawing.Color.FromArgb(136, 198, 237); dataGridViewCellStyle2.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0); dataGridViewCellStyle2.ForeColor = System.Drawing.Color.FromArgb(64, 64, 64); dataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight; dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText; dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.True; ColumnHeadersDefaultCellStyle = dataGridViewCellStyle2; ColumnHeadersHeight = 35; ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing; System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle(); dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; dataGridViewCellStyle3.BackColor = System.Drawing.Color.FromArgb(136, 198, 237); dataGridViewCellStyle3.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 136); dataGridViewCellStyle3.ForeColor = System.Drawing.Color.FromArgb(64, 64, 64); dataGridViewCellStyle3.SelectionBackColor = System.Drawing.SystemColors.Highlight; dataGridViewCellStyle3.SelectionForeColor = System.Drawing.SystemColors.HighlightText; dataGridViewCellStyle3.WrapMode = System.Windows.Forms.DataGridViewTriState.True; EnableHeadersVisualStyles = true; RowHeadersDefaultCellStyle = dataGridViewCellStyle3; RowHeadersWidth = 25; TabIndex = 4; GridColor = System.Drawing.SystemColors.Window; DoubleBuffered = true; CellDoubleClick += new System.Windows.Forms.DataGridViewCellEventHandler(StyledDataGridView_CellDoubleClick); CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(StyledDataGridView_CellClick); CellEnter += new System.Windows.Forms.DataGridViewCellEventHandler(StyledDataGridView_CellEnter); this.EditingControlShowing += new DataGridViewEditingControlShowingEventHandler(StyledDataGridView_EditingControlShowing); ResumeLayout(); }