/// <summary> /// 创建DataGridView扩展的IntegerInput列 /// </summary> /// <param name="_dgv">要创建列的DataGridView</param> /// <param name="_alignment">设置列的对齐方式</param> /// <param name="_columnName">列名</param> /// <param name="_headerText">标题名</param> /// <param name="_dataPropertyName">绑定数据源的字段名称</param> /// <param name="_toolTipText">TipText提示</param> /// <param name="_showUpDown">设置列是否显示上下可调节按钮,true 显示,false 隐藏</param> /// <param name="_readOnly">设置列是否只读,true 只读,false 读写</param> /// <param name="_visible">设置列是否可见,true 显示,false 隐藏</param> /// <param name="_notEmpty">设置列是否为必填列,true 必填,false 非必填</param> /// <param name="_backColor">设置列的背景色,当_notEmpty为true时,此项为必需值,为false,此项可以为Color.Empty</param> /// <param name="_columnState">装载DataGridView可写可读、只读列的数据字典</param> public static void InitDgvIntegerInputColumn(DataGridView _dgv, DataGridViewContentAlignment _alignment, string _columnName, string _headerText, string _dataPropertyName, string _toolTipText, bool _showUpDown, bool _readOnly, bool _visible, bool _notEmpty, Color _backColor, ref Dictionary <string, bool> _columnState) { DataGridViewIntegerInputColumn integerInputCol = new DataGridViewIntegerInputColumn(); integerInputCol.HeaderCell.Style.Alignment = _alignment == 0 ? DataGridViewContentAlignment.MiddleLeft : _alignment; integerInputCol.Name = _columnName; integerInputCol.HeaderText = _headerText; integerInputCol.DataPropertyName = _dataPropertyName; integerInputCol.ToolTipText = _toolTipText; integerInputCol.ShowUpDown = _showUpDown; integerInputCol.Visible = _visible; integerInputCol.ReadOnly = _readOnly; integerInputCol.InputHorizontalAlignment = DevComponents.Editors.eHorizontalAlignment.Right; if (_notEmpty == true) { integerInputCol.DefaultCellStyle.BackColor = _backColor; } _columnState.Add(_columnName, _readOnly); _dgv.Columns.Add(integerInputCol); }
public DataGridViewColumn[] ColumnasGrid() { DataGridViewTextBoxColumn colIdUsuario = new DataGridViewTextBoxColumn() { Name = "colIdUsuario", HeaderText = "Id", DataPropertyName = "Id", AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells }; colIdUsuario.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; /*DataGridViewTextBoxDropDownColumn colIdentificacion = new DataGridViewTextBoxDropDownColumn() * { * Name = "colIdentificacion", * HeaderText = "Identificacion", * DataPropertyName = "Identificacion", * AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells * * };*/ /*colIdentificacion.MaxInputLength = 13; * //colIdentificacion.ButtonCustomClick += colIdentificacion_ButtonCustomClick; * colIdentificacion.ButtonDropDownClick += new EventHandler<System.ComponentModel.CancelEventArgs>(colIdentificacion_ButtonDropDownClick); * //colIdentificacion.ButtonCustom.Visible = true; * colIdentificacion.ButtonDropDown.Visible = true; * //colIdentificacion.ButtonCustom.Shortcut = DevComponents.DotNetBar.eShortcut.F4; * colIdentificacion.ButtonDropDown.Shortcut = DevComponents.DotNetBar.eShortcut.F4; * colIdentificacion.ButtonDropDown.Image = General.Imagenes.Images["Listar.ico"]; * colIdentificacion.Tag = "colDescripcion"; * colIdentificacion.ButtonDropDown.ItemReference.Focusable = true; */ DataGridViewTextBoxColumn colIdentificacion = new DataGridViewTextBoxColumn() { Name = "colIdentificacion", HeaderText = "Identificacion.", DataPropertyName = "identificacion", AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells, Tag = "colDescripcion" }; DataGridViewButtonXColumn colIdeBoton = new DataGridViewButtonXColumn() { Name = "colIdeBoton", HeaderText = "->", AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells, Tag = "colIdentificacion", Image = General.Imagenes.Images["Listar.ico"], ColorTable = DevComponents.DotNetBar.eButtonColor.Blue }; colIdeBoton.DefaultCellStyle.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(192))))); DataGridViewTextBoxColumn colPersona = new DataGridViewTextBoxColumn() { Name = "colPersona", HeaderText = "Cliente", DataPropertyName = "fkpersona", AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells, ReadOnly = true }; colPersona.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft; DataGridViewTextBoxColumn colDescripcion = new DataGridViewTextBoxColumn() { Name = "colDescripcion", HeaderText = "Descripcion", DataPropertyName = "Descripcion", AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells }; colDescripcion.MaxInputLength = 40; DataGridViewCheckBoxColumn colAdministrador = new DataGridViewCheckBoxColumn() { Name = "colAdministrador", HeaderText = "Administrador", DataPropertyName = "Administrador", AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader }; DataGridViewIntegerInputColumn colDiasVigencia = new DataGridViewIntegerInputColumn() { Name = "colDiasVigencia", HeaderText = "VigenciaClave", DataPropertyName = "DiasVigencia", MinValue = 0, MaxValue = 360, MaxInputLength = 2, AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader, ToolTipText = "Dias de vigencia de la clave" }; colDiasVigencia.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; colDiasVigencia.ShowUpDown = true; DataGridViewDateTimeInputColumn colFechaCambioChr = new DataGridViewDateTimeInputColumn() { Name = "colFechaCambioChr", HeaderText = "Modificado", DataPropertyName = "FechaCambioChr", Format = DevComponents.Editors.eDateTimePickerFormat.Custom, CustomFormat = "yyyy-MM-dd", MinDate = new DateTime(1920, 02, 01), AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells }; DataGridViewTextBoxColumn colLoginUsuario = new DataGridViewTextBoxColumn() { Name = "colLoginUsuario", HeaderText = "Login", DataPropertyName = "loginusuario", AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells }; DataGridViewCheckBoxColumn colActivo = new DataGridViewCheckBoxColumn() { Name = "colActivo", HeaderText = "Activo", DataPropertyName = "Activo", AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader }; DataGridViewCheckBoxColumn colReseteaClave = new DataGridViewCheckBoxColumn() { Name = "colReseteaClave", HeaderText = "Resetea clave", DataPropertyName = "ReseteaClave", AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader }; DataGridViewDateTimeInputColumn colFechaCreacionChr = new DataGridViewDateTimeInputColumn() { Name = "colFechaCreacionChr", HeaderText = "Creado", DataPropertyName = "FechaCreacionChr", Format = DevComponents.Editors.eDateTimePickerFormat.Custom, CustomFormat = "yyyy-MM-dd", MinDate = new DateTime(1901, 02, 01), AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells }; DataGridViewCheckBoxColumn colModificado = new DataGridViewCheckBoxColumn() { Name = "colModificado", HeaderText = "Modificado", DataPropertyName = "Modificado", Visible = false }; DataGridViewColumn[] listaColumnas = new DataGridViewColumn[] { colIdUsuario, //colIdentificacion, colIdentificacion, colIdeBoton, colPersona, colDescripcion, colLoginUsuario, colDiasVigencia, colAdministrador, colActivo, colFechaCreacionChr, colFechaCambioChr, colReseteaClave, colModificado }; return(listaColumnas); }
private void PopulateColumns() { BusyPopulatingColumns = true; EditColumns.Clear(); dataGridViewX1.Columns.Clear(); if (ShowDeleteColumn) { DataGridViewImageColumn col = new DataGridViewImageColumn(); col.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; col.DefaultCellStyle.NullValue = DeleteImage; col.HeaderText = ""; col.Frozen = FrozenColumnIndex.HasValue; dataGridViewX1.Columns.Add(col); } for (int i = 0; i < Columns.Count; i++) { ColumnItem column = Columns[i]; //DataGridViewColumn colNullableCheckbox = null; DataGridViewColumn col = null; switch (column.ControlType) { case ColumnItem.ColumnTypes.Checkbox: col = new DataGridViewCheckBoxColumn(); break; case ColumnItem.ColumnTypes.Textbox: col = new DataGridViewTextBoxColumnEx(); ((DataGridViewTextBoxColumnEx)col).DisabledColor = DisabledColor; ((DataGridViewTextBoxColumnEx)col).InvalidColor = InvalidColor; ((DataGridViewTextBoxColumnEx)col).BackColor = BackColor; break; case ColumnItem.ColumnTypes.IntegerInput: col = new DataGridViewIntegerInputColumn(); ((DataGridViewIntegerInputColumn)col).DisplayControlForCurrentCellOnly = true; ((DataGridViewIntegerInputColumn)col).BackgroundStyle.Border = eStyleBorderType.None; ((DataGridViewIntegerInputColumn)col).ShowUpDown = true; break; case ColumnItem.ColumnTypes.NullableCheckBox: col = new DataGridViewComboBoxColumnEx(); List <string> vals = new List <string>(new string[] { "", "True", "False" }); ((DataGridViewComboBoxColumnEx)col).DataSource = vals; ((DataGridViewComboBoxColumnEx)col).DisplayStyle = DataGridViewComboBoxDisplayStyle.ComboBox; ((DataGridViewComboBoxColumnEx)col).FlatStyle = FlatStyle.Flat; ((DataGridViewComboBoxColumnEx)col).DisabledColor = DisabledColor; ((DataGridViewComboBoxColumnEx)col).InvalidColor = InvalidColor; ((DataGridViewComboBoxColumnEx)col).BackColor = BackColor; break; case ColumnItem.ColumnTypes.NullableTextBox: col = new DataGridViewTextBoxColumnEx(); ((DataGridViewTextBoxColumnEx)col).DisabledColor = DisabledColor; ((DataGridViewTextBoxColumnEx)col).InvalidColor = InvalidColor; ((DataGridViewTextBoxColumnEx)col).BackColor = BackColor; break; case ColumnItem.ColumnTypes.NullableIntegerInput: col = new DataGridViewTextBoxColumnEx(); ((DataGridViewTextBoxColumnEx)col).DisabledColor = DisabledColor; ((DataGridViewTextBoxColumnEx)col).InvalidColor = InvalidColor; ((DataGridViewTextBoxColumnEx)col).BackColor = BackColor; ((DataGridViewTextBoxColumnEx)col).Alignment = DataGridViewContentAlignment.MiddleRight; break; case ColumnItem.ColumnTypes.ComboBox: col = new DataGridViewComboBoxColumnEx(); List <string> keys = column.ComboItems.Keys.ToList(); keys.Sort(); ((DataGridViewComboBoxColumnEx)col).DataSource = keys; ((DataGridViewComboBoxColumnEx)col).DisplayStyle = DataGridViewComboBoxDisplayStyle.ComboBox; ((DataGridViewComboBoxColumnEx)col).FlatStyle = FlatStyle.Flat; ((DataGridViewComboBoxColumnEx)col).DisabledColor = DisabledColor; ((DataGridViewComboBoxColumnEx)col).InvalidColor = InvalidColor; ((DataGridViewComboBoxColumnEx)col).BackColor = BackColor; break; case ColumnItem.ColumnTypes.Image: col = new DataGridViewImageColumn(); break; case ColumnItem.ColumnTypes.Link: col = new DataGridViewLinkColumn(); break; case ColumnItem.ColumnTypes.None: col = new DataGridViewLinkColumn(); break; default: throw new NotImplementedException("Not handled yet"); } //if (colNullableCheckbox != null) //{ // colNullableCheckbox.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;// true; // colNullableCheckbox.Resizable = DataGridViewTriState.False;// false; // dataGridViewX1.Columns.Add(colNullableCheckbox); //} col.Frozen = (FrozenColumnIndex.HasValue && i < FrozenColumnIndex); col.HeaderText = column.Text; col.AutoSizeMode = DataGridViewAutoSizeColumnMode.None; //.AllCells; col.Resizable = DataGridViewTriState.True; col.ReadOnly = column.ReadOnly; dataGridViewX1.Columns.Add(col); EditColumns.Add(dataGridViewX1.Columns.Count - 1, i); } //dataGridViewX1.Columns[1].Frozen = true; BusyPopulatingColumns = false; }