private bool sorted;
private string valueMember;
+ private DataGridViewComboBoxEditingControl editingControl;
+
public DataGridViewComboBoxCell () : base() {
autoComplete = true;
dataSource = null;
sorted = false;
}
+ [DefaultValue (true)]
public virtual bool AutoComplete {
get { return autoComplete; }
set { autoComplete = value; }
}
}
+ [DefaultValue ("")]
public virtual string DisplayMember {
get { return displayMember; }
set { displayMember = value; }
}
+ [DefaultValue (DataGridViewComboBoxDisplayStyle.DropDownButton)]
public DataGridViewComboBoxDisplayStyle DisplayStyle {
get { return displayStyle; }
set { displayStyle = value; }
}
+ [DefaultValue (false)]
public bool DisplayStyleForCurrentCellOnly {
get { return displayStyleForCurrentCellOnly; }
set { displayStyleForCurrentCellOnly = value; }
}
+ [DefaultValue (1)]
public virtual int DropDownWidth {
get { return dropDownWidth; }
set {
get { return typeof(DataGridViewComboBoxEditingControl); }
}
+ [DefaultValue (FlatStyle.Standard)]
public FlatStyle FlatStyle {
get { return flatStyle; }
set {
get { return typeof(string); }
}
+ [Browsable (false)]
public virtual ObjectCollection Items {
get { return items; }
}
+ [DefaultValue (8)]
public virtual int MaxDropDownItems {
get { return maxDropDownItems; }
set {
}
}
+ [DefaultValue (false)]
public virtual bool Sorted {
get { return sorted; }
set {
}
}
+ [DefaultValue ("")]
public virtual string ValueMember {
get { return valueMember; }
set { valueMember = value; }
}
public override void DetachEditingControl () {
- throw new NotImplementedException();
+ this.DataGridView.EditingControlInternal = null;
}
public override void InitializeEditingControl (int rowIndex, object initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle) {
- throw new NotImplementedException();
+ base.InitializeEditingControl (rowIndex, initialFormattedValue, dataGridViewCellStyle);
+
+ editingControl = DataGridView.EditingControl as DataGridViewComboBoxEditingControl;
+
+ if (editingControl == null)
+ return;
+
+ // A simple way to check if the control has
+ // been initialized already.
+ if (editingControl.Items.Count > 0)
+ return;
+
+ editingControl.DropDownStyle = ComboBoxStyle.DropDownList;
+ editingControl.Text = initialFormattedValue == null ? string.Empty : initialFormattedValue.ToString ();
+ editingControl.SelectedIndexChanged += new EventHandler (editingControl_SelectedIndexChanged);
+ editingControl.Items.Clear ();
+ editingControl.Items.AddRange (this.Items);
+ }
+
+ void editingControl_SelectedIndexChanged (object sender, EventArgs e)
+ {
+ Value = editingControl.SelectedItem;
}
public override bool KeyEntersEditMode (KeyEventArgs e) {
}
public override string ToString () {
- throw new NotImplementedException();
+ return string.Format ("DataGridViewComboBoxCell {{ ColumnIndex={0}, RowIndex={1} }}", ColumnIndex, RowIndex);
}
protected override Rectangle GetContentBounds (Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex) {
throw new NotImplementedException();
}
- protected override Rectangle GetErrorIconBounds (Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex) {
- throw new NotImplementedException();
+ protected override Rectangle GetErrorIconBounds (Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex)
+ {
+ if (DataGridView == null || string.IsNullOrEmpty (ErrorText))
+ return Rectangle.Empty;
+
+ Size error_icon = new Size (12, 11);
+ return new Rectangle (new Point (Size.Width - error_icon.Width - 23, (Size.Height - error_icon.Height) / 2), error_icon);
}
protected override object GetFormattedValue (object value, int rowIndex, ref DataGridViewCellStyle cellStyle, TypeConverter valueTypeConverter, TypeConverter formattedValueTypeConverter, DataGridViewDataErrorContexts context) {
}
protected override void OnDataGridViewChanged () {
- throw new NotImplementedException();
+ // Here we're supposed to do something with DataSource, etc, according to MSDN.
+ base.OnDataGridViewChanged ();
}
protected override void OnEnter (int rowIndex, bool throughMouseClick) {
- throw new NotImplementedException();
+ base.OnEnter (rowIndex, throughMouseClick);
}
protected override void OnLeave (int rowIndex, bool throughMouseClick) {
- throw new NotImplementedException();
+ base.OnLeave (rowIndex, throughMouseClick);
}
protected override void OnMouseClick (DataGridViewCellMouseEventArgs e) {
- throw new NotImplementedException();
+ base.OnMouseClick (e);
}
protected override void OnMouseEnter (int rowIndex) {
- throw new NotImplementedException();
+ base.OnMouseEnter (rowIndex);
}
protected override void OnMouseLeave (int rowIndex) {
- throw new NotImplementedException();
+ base.OnMouseLeave (rowIndex);
}
protected override void OnMouseMove (DataGridViewCellMouseEventArgs e) {
- throw new NotImplementedException();
+ //Console.WriteLine ("MouseMove (Location: {0}", e.Location);
+ base.OnMouseMove (e);
+ }
+
+ protected override void Paint (Graphics graphics, Rectangle clipBounds, Rectangle cellBounds,
+ int rowIndex, DataGridViewElementStates elementState, object value,
+ object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle,
+ DataGridViewPaintParts paintParts) {
+
+
+ Rectangle button_area, text_area;
+ text_area = cellBounds;
+ button_area = CalculateButtonArea (cellBounds);
+
+ graphics.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (cellStyle.BackColor), cellBounds);
+ ThemeEngine.Current.CPDrawComboButton (graphics, button_area, ButtonState.Normal);
+
+ string text;
+ if (formattedValue == null)
+ text = string.Empty;
+ else {
+ text = formattedValue.ToString ();
+ }
+
+ graphics.DrawString (text, cellStyle.Font, ThemeEngine.Current.ResPool.GetSolidBrush (cellStyle.ForeColor), text_area, StringFormat.GenericTypographic);
}
- protected override void Paint (Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementeState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) {
- throw new NotImplementedException();
+ private Rectangle CalculateButtonArea (Rectangle cellBounds)
+ {
+ Rectangle button_area, text_area;
+ int border = ThemeEngine.Current.Border3DSize.Width;
+ const int button_width = 16;
+
+ text_area = cellBounds;
+
+ button_area = cellBounds;
+ button_area.X = text_area.Right - button_width - border;
+ button_area.Y = text_area.Y + border;
+ button_area.Width = button_width;
+ button_area.Height = text_area.Height - 2 * border;
+
+ return button_area;
}
+ [ListBindable (false)]
public class ObjectCollection : IList, ICollection, IEnumerable {
private ArrayList list;
- private DataGridViewComboBoxCell owner;
+ //private DataGridViewComboBoxCell owner;
public ObjectCollection (DataGridViewComboBoxCell owner) {
- this.owner = owner;
+ //this.owner = owner;
list = new ArrayList();
}
- public virtual int Count {
+ public int Count {
get { return list.Count; }
}
- public virtual bool IsFixedSize {
+ bool IList.IsFixedSize {
get { return list.IsFixedSize; }
}
- public virtual bool IsReadOnly {
+ public bool IsReadOnly {
get { return list.IsReadOnly; }
}
- public virtual bool IsSynchronized {
+ bool ICollection.IsSynchronized {
get { return list.IsSynchronized; }
}
- public virtual object SyncRoot {
+ object ICollection.SyncRoot {
get { return list.SyncRoot; }
}
list.AddRange(value.list);
}
- public void AddRange (object[] items) {
+ public void AddRange (params object[] items) {
list.AddRange(items);
}
- //public sealed void Clear () {
public void Clear () {
list.Clear();
}
- //public sealed bool Contains (object value) {
public bool Contains (object value) {
return list.Contains(value);
}
- public void CopyTo (Array destination, int arrayIndex) {
- list.CopyTo(destination, arrayIndex);
+ void ICollection.CopyTo (Array destination, int index)
+ {
+ CopyTo ((object[]) destination, index);
+ }
+
+ public void CopyTo (object[] destination, int arrayIndex)
+ {
+ list.CopyTo (destination, arrayIndex);
}
- //public sealed IEnumerator GetEnumerator () {
public IEnumerator GetEnumerator () {
return list.GetEnumerator();
}
- //public sealed int IndexOf (object value) {
public int IndexOf (object value) {
return list.IndexOf(value);
}
- //public sealed void Insert (int index, object item) {
public void Insert (int index, object item) {
list.Insert(index, item);
}
- //public sealed void Remove (object value) {
public void Remove (object value) {
list.Remove(value);
}
- //public sealed void RemoveAt (int index) {
public void RemoveAt (int index) {
list.RemoveAt(index);
}
+
+ int IList.Add (object item)
+ {
+ return Add (item);
+ }
+
}
}