Welcome to mirror list, hosted at ThFree Co, Russian Federation.

DataGridViewColumn.cs « System.Windows.Forms « Managed.Windows.Forms « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: de61e7ab632cf926224967b7b5860e24108713ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
//
// Author:
//	Pedro Martínez Juliá <pedromj@gmail.com>
//


#if NET_2_0

using System;
using System.ComponentModel;

namespace System.Windows.Forms {

	[Designer ("System.Windows.Forms.Design.DataGridViewColumnDesigner, " + Consts.AssemblySystem_Design,
		   "System.ComponentModel.Design.IDesigner")]
	[TypeConverter (typeof (DataGridViewColumnConverter))]
	[ToolboxItem ("")]
	[DesignTimeVisible (false)]
	public class DataGridViewColumn : DataGridViewBand, IComponent, IDisposable {
		private bool auto_generated;
		private DataGridViewAutoSizeColumnMode autoSizeMode;
		private DataGridViewCell cellTemplate;
		private ContextMenuStrip contextMenuStrip;
		private string dataPropertyName;
		private int displayIndex;
		private int dividerWidth;
		private float fillWeight;
		private bool frozen;
		private DataGridViewColumnHeaderCell headerCell;
		private bool isDataBound;
		private int minimumWidth = 5;
		private string name = "";
		private bool readOnly;
		private ISite site;
		private DataGridViewColumnSortMode sortMode;
		private string toolTipText;
		private Type valueType;
		private bool visible = true;
		private int width = 100;

		private bool headerTextSet = false;

		public DataGridViewColumn () {
			cellTemplate = null;
			base.DefaultCellStyle = new DataGridViewCellStyle();
			readOnly = false;
			headerCell = new DataGridViewColumnHeaderCell();
			headerCell.SetColumnIndex(Index);
			headerCell.Value = string.Empty;
			displayIndex = -1;
			dataPropertyName = string.Empty;
			fillWeight = 100.0F;
			sortMode = DataGridViewColumnSortMode.NotSortable;
			SetState (DataGridViewElementStates.Visible);
		}

		public DataGridViewColumn (DataGridViewCell cellTemplate) : this () {
			this.cellTemplate = (DataGridViewCell) cellTemplate.Clone();
		}

		[DefaultValue (DataGridViewAutoSizeColumnMode.NotSet)]
		[RefreshProperties (RefreshProperties.Repaint)]
		public DataGridViewAutoSizeColumnMode AutoSizeMode {
			get { return autoSizeMode; }
			set {
				if (autoSizeMode != value) {
					DataGridViewAutoSizeColumnMode old_value = autoSizeMode;
					autoSizeMode = value;
					
					if (DataGridView != null) {
						DataGridView.OnAutoSizeColumnModeChanged (new DataGridViewAutoSizeColumnModeEventArgs (this, old_value));
						DataGridView.AutoResizeColumnsInternal ();
					}
				}
			}
		}

		[Browsable (false)]
		[EditorBrowsable (EditorBrowsableState.Advanced)]
		[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
		public virtual DataGridViewCell CellTemplate {
			get { return cellTemplate; }
			set { cellTemplate = value; }
		}

		[Browsable (false)]
		[EditorBrowsable (EditorBrowsableState.Advanced)]
		public Type CellType {
			get {
				if (cellTemplate == null) {
					return null;
				}
				return cellTemplate.GetType();
			}
		}

		[DefaultValue (null)]
		public override ContextMenuStrip ContextMenuStrip {
			get { return contextMenuStrip; }
			set {
				if (contextMenuStrip != value) {
					contextMenuStrip = value;
					if (DataGridView != null) {
						DataGridView.OnColumnContextMenuStripChanged(new DataGridViewColumnEventArgs(this));
					}
				}
			}
		}

		[Browsable (true)]
		[DefaultValue ("")]
		[Editor ("System.Windows.Forms.Design.DataGridViewColumnDataPropertyNameEditor, " + Consts.AssemblySystem_Design,
			 typeof (System.Drawing.Design.UITypeEditor))]
		[TypeConverter ("System.Windows.Forms.Design.DataMemberFieldConverter, " + Consts.AssemblySystem_Design)]
		public string DataPropertyName {
			get { return dataPropertyName; }
			set {
				if (dataPropertyName != value) {
					dataPropertyName = value;
					if (DataGridView != null) {
						DataGridView.OnColumnDataPropertyNameChanged(new DataGridViewColumnEventArgs(this));
					}
				}
			}
		}

		[Browsable (true)]
		public override DataGridViewCellStyle DefaultCellStyle {
			get {
				return base.DefaultCellStyle;
			}
			set {
				if (DefaultCellStyle != value) {
					base.DefaultCellStyle = value;
					if (DataGridView != null) {
						DataGridView.OnColumnDefaultCellStyleChanged(new DataGridViewColumnEventArgs(this));
					}
				}
			}
		}

		[Browsable (false)]
		[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
		public int DisplayIndex {
			get {
				if (displayIndex < 0) {
					return Index;
				}
				return displayIndex;
			}
			set {
				if (displayIndex != value) {
					if (value < 0 || value > Int32.MaxValue) {
						throw new ArgumentOutOfRangeException("DisplayIndex is out of range");
					}
					displayIndex = value;
					if (DataGridView != null) {
						DataGridView.Columns.RegenerateSortedList ();
						DataGridView.OnColumnDisplayIndexChanged(new DataGridViewColumnEventArgs(this));
					}
				}
			}
		}

		[DefaultValue (0)]
		public int DividerWidth {
			get { return dividerWidth; }
			set {
				if (dividerWidth != value) {
					dividerWidth = value;
					if (DataGridView != null) {
						DataGridView.OnColumnDividerWidthChanged(new DataGridViewColumnEventArgs(this));
					}
				}
			}
		}

		[DefaultValue (100)]
		public float FillWeight {
			get { return fillWeight; }
			set {
				fillWeight = value;
				/* When the System.Windows.Forms.DataGridViewColumn.InheritedAutoSizeMode property value is System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill, the column is resized along with other columns in that mode so that all visible columns in the control exactly fill the horizontal width of the available display area. All fill-mode columns in the control divide the available space in proportions determined by their System.Windows.Forms.DataGridViewColumn.FillWeight property values. For more information about column fill mode, see Column Fill Mode in the Windows Forms DataGridView Control.

The maximum sum of System.Windows.Forms.DataGridViewColumn.FillWeight values for all columns in a System.Windows.Forms.DataGridView control is 65535.
				*/
			}
		}

		[DefaultValue (false)]
		[RefreshProperties (RefreshProperties.All)]
		public override bool Frozen {
			get { return frozen; }
			set { frozen = value; }
		}
		/* When a column is frozen, all the columns to its left (or to its right in right-to-left languages) are frozen as well. The frozen and unfrozen columns form two groups. If column repositioning is enabled by setting the System.Windows.Forms.DataGridView.AllowUserToOrderColumns property to true, the user cannot drag a column from one group to the other.
Example */

		[Browsable (false)]
		[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
		public DataGridViewColumnHeaderCell HeaderCell {
			get {
				return headerCell;
			}
			set {
				if (headerCell != value) {
					headerCell = value;
					if (DataGridView != null) {
						DataGridView.OnColumnHeaderCellChanged(new DataGridViewColumnEventArgs(this));
					}
				}
			}
		}

		[Localizable (true)]
		public string HeaderText {
			get {
				if (headerCell.Value == null) {
					return String.Empty;
				}
				return (string) headerCell.Value;
			}
			set {
				headerCell.Value = value;
				headerTextSet = true;
			}
		}

		internal bool AutoGenerated { get { return auto_generated; } set { auto_generated = value; } }
		internal bool HeaderTextSet { get { return headerTextSet; } }
		
		[Browsable (false)]
		[EditorBrowsable (EditorBrowsableState.Advanced)]
		[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
		public DataGridViewAutoSizeColumnMode InheritedAutoSizeMode {
			get {
				if (this.DataGridView == null)
					return this.autoSizeMode;
				
				if (this.autoSizeMode != DataGridViewAutoSizeColumnMode.NotSet)
					return this.autoSizeMode;
				
				switch (this.DataGridView.AutoSizeColumnsMode) {
				case DataGridViewAutoSizeColumnsMode.AllCells:
					return DataGridViewAutoSizeColumnMode.AllCells;
				case DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader:
					return DataGridViewAutoSizeColumnMode.AllCellsExceptHeader;
				case DataGridViewAutoSizeColumnsMode.ColumnHeader:
					return DataGridViewAutoSizeColumnMode.ColumnHeader;
				case DataGridViewAutoSizeColumnsMode.DisplayedCells:
					return DataGridViewAutoSizeColumnMode.DisplayedCells;
				case DataGridViewAutoSizeColumnsMode.DisplayedCellsExceptHeader:
					return DataGridViewAutoSizeColumnMode.DisplayedCellsExceptHeader;
				case DataGridViewAutoSizeColumnsMode.Fill:
					return DataGridViewAutoSizeColumnMode.Fill;
				default:
					return DataGridViewAutoSizeColumnMode.None;
				}				
			}
		}

		[Browsable (false)]
		public override DataGridViewCellStyle InheritedStyle {
			get {
				if (DataGridView == null) {
					return base.DefaultCellStyle;
				}
				else {
					if (base.DefaultCellStyle == null) {
						return DataGridView.DefaultCellStyle;
					}
					else {
						DataGridViewCellStyle style = (DataGridViewCellStyle) base.DefaultCellStyle.Clone();
						/////// Combination with dataGridView.DefaultCellStyle
						return style;
					}
				}
			}
		}

		[Browsable (false)]
		[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
		public bool IsDataBound {
			get { return isDataBound; }
		}

		[DefaultValue (5)]
		[RefreshProperties (RefreshProperties.Repaint)]
		[Localizable (true)]
		public int MinimumWidth {
			get { return minimumWidth; }
			set {
				if (minimumWidth != value) {
					if (value < 2 || value > Int32.MaxValue) {
						throw new ArgumentOutOfRangeException("MinimumWidth is out of range");
					}
					minimumWidth = value;
					if (DataGridView != null) {
						DataGridView.OnColumnMinimumWidthChanged(new DataGridViewColumnEventArgs(this));
					}
				}
			}
		}

		[Browsable (false)]
		public string Name {
			get { return name; }
			set {
				if (name != value) {
					if (value == null)
						name = string.Empty;
					else
						name = value;
					if (!headerTextSet) {
						headerCell.Value = name;
					}
					if (DataGridView != null) {
						DataGridView.OnColumnNameChanged(new DataGridViewColumnEventArgs(this));
					}
				}
			}
		}

		public override bool ReadOnly {
			get {

				if (DataGridView != null && DataGridView.ReadOnly)
					return true;

				return readOnly;
			}
			set { readOnly = value; }
		}

		public override DataGridViewTriState Resizable {
			get { return base.Resizable; }
			set { base.Resizable = value; }
		}

		[Browsable (false)]
		[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
		public ISite Site {
			get { return site; }
			set { site = value; }
		}

		[DefaultValue (DataGridViewColumnSortMode.NotSortable)]
		public DataGridViewColumnSortMode SortMode {
			get { return sortMode; }
			set {
				if (DataGridView != null && value == DataGridViewColumnSortMode.Automatic) {
					if (DataGridView.SelectionMode == DataGridViewSelectionMode.FullColumnSelect ||
					    DataGridView.SelectionMode == DataGridViewSelectionMode.ColumnHeaderSelect)
						throw new InvalidOperationException ("Column's SortMode cannot be set to Automatic "+
										     "while the DataGridView control's SelectionMode "+
										     "is set to FullColumnSelect or ColumnHeaderSelect.");
				}

				if (sortMode != value) {
					sortMode = value;
					if (DataGridView != null) {
						DataGridView.OnColumnSortModeChanged(new DataGridViewColumnEventArgs(this));
					}
				}
			}
		}

		[DefaultValue ("")]
		[Localizable (true)]
		public string ToolTipText {
			get {
				if (toolTipText == null)
					return string.Empty;
				return toolTipText; }
			set {
				if (toolTipText != value) {
					toolTipText = value;
					if (DataGridView != null) {
						DataGridView.OnColumnToolTipTextChanged(new DataGridViewColumnEventArgs(this));
					}
				}
			}
		}

		[Browsable (false)]
		[DefaultValue (null)]
		[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
		public Type ValueType {
			get { return valueType; }
			set { valueType = value; }
		}

		[DefaultValue (true)]
		[Localizable (true)]
		public override bool Visible {
			get { return visible; }
			set {
				visible = value;
				if (DataGridView != null)
					DataGridView.Invalidate ();
			}
		}

		[Localizable (true)]
		[RefreshProperties (RefreshProperties.Repaint)]
		public int Width {
			get { return width; }
			set {
				if (width != value) {
					if (value < minimumWidth) {
						throw new ArgumentOutOfRangeException("Width is less than MinimumWidth");
					}
					width = value;
					if (DataGridView != null)  {
						DataGridView.Invalidate ();
						DataGridView.OnColumnWidthChanged(new DataGridViewColumnEventArgs(this));
					}

				}
			}
		}

		// XXX should we do something like Component.Events?
		[Browsable (false)]
		[EditorBrowsable (EditorBrowsableState.Advanced)]
		public event EventHandler Disposed;

		public override object Clone () {
			return this.MemberwiseClone();
			/*
			DataGridViewColumn result = new DataGridViewColumn();
			return result;
			*/
		}

		public virtual int GetPreferredWidth (DataGridViewAutoSizeColumnMode autoSizeColumnMode, bool fixedHeight) {
			switch (autoSizeColumnMode) {
			case DataGridViewAutoSizeColumnMode.NotSet:
			case DataGridViewAutoSizeColumnMode.None:
			case DataGridViewAutoSizeColumnMode.Fill:
				throw new ArgumentException("AutoSizeColumnMode is invalid");
			}
			if (fixedHeight) {
				return 0;
			}
			else {
				return 0;
			}
		}

		public override string ToString () {
			return Name + ", Index: " + base.Index.ToString() + ".";
		}

		protected override void Dispose (bool disposing) {
			if (disposing) {
			}
		}

		internal override void SetDataGridView (DataGridView dataGridView) {
			if (sortMode == DataGridViewColumnSortMode.Automatic && dataGridView != null && dataGridView.SelectionMode == DataGridViewSelectionMode.FullColumnSelect) {
				throw new InvalidOperationException ("Column's SortMode cannot be set to Automatic while the DataGridView control's SelectionMode is set to FullColumnSelect.");
			}
			
			base.SetDataGridView (dataGridView);
			headerCell.SetDataGridView(dataGridView);
		}

		internal override void SetIndex (int index) {
			base.SetIndex(index);
			headerCell.SetColumnIndex(Index);
		}

		internal void SetIsDataBound (bool value)
		{
			isDataBound = value;
		}
		
		internal override void SetState (DataGridViewElementStates state) {
			if (State != state) {
				base.SetState(state);
				if (DataGridView != null) {
					DataGridView.OnColumnStateChanged(new DataGridViewColumnStateChangedEventArgs(this, state));
				}
			}
		}

	}
	
	internal class DataGridViewColumnConverter : TypeConverter
	{
	}
}

#endif