// Pedro MartÃnez Juliá <pedromj@gmail.com>
//
-
-#if NET_2_0
+using System.Collections;
+using System.ComponentModel;
+using System.Drawing.Design;
+using System.Drawing;
namespace System.Windows.Forms {
- public class DataGridViewComboBoxColumn : DataGridViewColumn {
-
+ [ToolboxBitmap ("")]
+ [Designer ("System.Windows.Forms.Design.DataGridViewComboBoxColumnDesigner, " + Consts.AssemblySystem_Design,
+ "System.ComponentModel.Design.IDesigner")]
+ public class DataGridViewComboBoxColumn : DataGridViewColumn
+ {
private bool autoComplete;
private DataGridViewComboBoxDisplayStyle displayStyle;
- private bool displayStyleForCurrentCellsOnly;
+ private bool displayStyleForCurrentCellOnly;
private FlatStyle flatStyle;
- public DataGridViewComboBoxColumn () {
+ public DataGridViewComboBoxColumn ()
+ {
CellTemplate = new DataGridViewComboBoxCell();
+ ((DataGridViewComboBoxCell) CellTemplate).OwningColumnTemplate = this;
SortMode = DataGridViewColumnSortMode.NotSortable;
autoComplete = true;
displayStyle = DataGridViewComboBoxDisplayStyle.DropDownButton;
- displayStyleForCurrentCellsOnly = false;
+ displayStyleForCurrentCellOnly = false;
}
+ [Browsable (true)]
+ [DefaultValue (true)]
public bool AutoComplete {
get { return autoComplete; }
set { autoComplete = value; }
}
+ [Browsable (false)]
+ [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public override DataGridViewCell CellTemplate {
get { return base.CellTemplate; }
- set { base.CellTemplate = value as DataGridViewComboBoxCell; }
+ set {
+
+ DataGridViewComboBoxCell cellTemplate = value as DataGridViewComboBoxCell;
+ if (cellTemplate == null)
+ throw new InvalidCastException ("Invalid cell tempalte type.");
+
+ cellTemplate.OwningColumnTemplate = this;
+ base.CellTemplate = cellTemplate;
+ }
}
+ [AttributeProvider (typeof (IListSource))]
+ [DefaultValue (null)]
+ [RefreshProperties (RefreshProperties.Repaint)]
public object DataSource {
get {
if (base.CellTemplate == null) {
}
}
+ [Editor ("System.Windows.Forms.Design.DataMemberFieldEditor, " + Consts.AssemblySystem_Design,
+ "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
+ [DefaultValue ("")]
+ [TypeConverter ("System.Windows.Forms.Design.DataMemberFieldConverter, " + Consts.AssemblySystem_Design)]
public string DisplayMember {
get {
if (base.CellTemplate == null) {
}
}
+ [DefaultValue (DataGridViewComboBoxDisplayStyle.DropDownButton)]
public DataGridViewComboBoxDisplayStyle DisplayStyle {
get { return displayStyle; }
set { displayStyle = value; }
}
- public bool DisplayStyleForCurrentCellsOnly {
- get { return displayStyleForCurrentCellsOnly; }
- set { displayStyleForCurrentCellsOnly = value; }
+ [DefaultValue (false)]
+ public bool DisplayStyleForCurrentCellOnly {
+ get { return displayStyleForCurrentCellOnly; }
+ set { displayStyleForCurrentCellOnly = value; }
}
+ [DefaultValue (1)]
public int DropDownWidth {
get {
if (base.CellTemplate == null) {
}
}
+ [DefaultValue (FlatStyle.Standard)]
public FlatStyle FlatStyle {
get { return flatStyle; }
set { flatStyle = value; }
}
+ [Editor ("System.Windows.Forms.Design.StringCollectionEditor, " + Consts.AssemblySystem_Design,
+ "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
+ [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
public DataGridViewComboBoxCell.ObjectCollection Items {
get {
if (base.CellTemplate == null) {
}
}
+ [DefaultValue (8)]
public int MaxDropDownItems {
get {
if (base.CellTemplate == null) {
}
}
+ [DefaultValue (false)]
public bool Sorted {
get {
if (base.CellTemplate == null) {
}
}
+ [DefaultValue ("")]
+ [Editor ("System.Windows.Forms.Design.DataMemberFieldEditor, " + Consts.AssemblySystem_Design,
+ "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
+ [TypeConverter ("System.Windows.Forms.Design.DataMemberFieldConverter, " + Consts.AssemblySystem_Design)]
public string ValueMember {
get {
if (base.CellTemplate == null) {
}
}
- public override object Clone () {
+ internal void SyncItems (IList items)
+ {
+ if (DataSource != null || DataGridView == null)
+ return;
+
+ for (int i = 0; i < DataGridView.RowCount; i++) {
+ DataGridViewComboBoxCell comboCell = DataGridView.Rows[i].Cells[base.Index] as DataGridViewComboBoxCell;
+ if (comboCell != null) {
+ comboCell.Items.ClearInternal ();
+ comboCell.Items.AddRangeInternal (this.Items);
+ }
+ }
+ }
+
+ public override object Clone ()
+ {
DataGridViewComboBoxColumn col = (DataGridViewComboBoxColumn) base.Clone();
col.autoComplete = this.autoComplete;
col.displayStyle = this.displayStyle;
- col.displayStyleForCurrentCellsOnly = this.displayStyleForCurrentCellsOnly;
+ col.displayStyleForCurrentCellOnly = this.displayStyleForCurrentCellOnly;
col.flatStyle = this.flatStyle;
col.CellTemplate = (DataGridViewComboBoxCell) this.CellTemplate.Clone();
return col;
}
- public override string ToString () {
+ public override string ToString ()
+ {
return GetType().Name;
}
}
}
-
-#endif