1 // Permission is hereby granted, free of charge, to any person obtaining
\r
2 // a copy of this software and associated documentation files (the
\r
3 // "Software"), to deal in the Software without restriction, including
\r
4 // without limitation the rights to use, copy, modify, merge, publish,
\r
5 // distribute, sublicense, and/or sell copies of the Software, and to
\r
6 // permit persons to whom the Software is furnished to do so, subject to
\r
7 // the following conditions:
\r
9 // The above copyright notice and this permission notice shall be
\r
10 // included in all copies or substantial portions of the Software.
\r
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
\r
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
\r
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
\r
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
\r
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
\r
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
\r
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
20 // Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
\r
23 // olivier Dufour olivier.duff@free.fr
\r
28 using System.Collections.Generic;
\r
29 using System.ComponentModel;
\r
31 using System.Drawing;
\r
33 namespace System.Windows.Forms
\r
35 [ToolboxBitmap ("")]
\r
36 public class DataGridViewLinkColumn : DataGridViewColumn
\r
39 public DataGridViewLinkColumn ()
\r
41 base.CellTemplate = new DataGridViewLinkCell ();
\r
44 public override object Clone ()
\r
46 DataGridViewLinkColumn clone = (DataGridViewLinkColumn)base.Clone ();
\r
47 clone.CellTemplate = (DataGridViewCell) this.CellTemplate.Clone ();
\r
51 public override string ToString ()
\r
53 return base.ToString ();
\r
56 #region private fields
\r
58 private string text = string.Empty;
\r
62 #region Public Properties
\r
64 public Color ActiveLinkColor {
\r
66 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;
\r
67 if (template == null)
\r
68 throw new InvalidOperationException ("CellTemplate is null when getting this property.");
\r
69 return template.ActiveLinkColor;
\r
72 if (this.ActiveLinkColor == value)
\r
75 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;
\r
76 if (template == null)
\r
77 throw new InvalidOperationException ("CellTemplate is null when getting this property.");
\r
79 template.ActiveLinkColor = value;
\r
81 foreach (DataGridViewRow row in DataGridView.Rows) {
\r
82 DataGridViewLinkCell cell = row.Cells[Index] as DataGridViewLinkCell;
\r
84 cell.ActiveLinkColor = value;
\r
86 DataGridView.InvalidateColumn (Index);
\r
91 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
\r
93 public override DataGridViewCell CellTemplate {
\r
94 get { return base.CellTemplate; }
\r
95 set { base.CellTemplate = value as DataGridViewLinkCell; }
\r
99 [DefaultValue (LinkBehavior.SystemDefault)]
\r
100 public LinkBehavior LinkBehavior {
\r
102 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;
\r
103 if (template == null)
\r
104 throw new InvalidOperationException ("CellTemplate is null when getting this property.");
\r
105 return template.LinkBehavior;
\r
108 if (this.LinkBehavior == value)
\r
111 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;
\r
112 if (template == null)
\r
113 throw new InvalidOperationException ("CellTemplate is null when getting this property.");
\r
115 template.LinkBehavior = value;
\r
116 foreach (DataGridViewRow row in DataGridView.Rows)
\r
118 DataGridViewLinkCell cell = row.Cells[Index] as DataGridViewLinkCell;
\r
120 cell.LinkBehavior = value;
\r
122 DataGridView.InvalidateColumn (Index);
\r
126 public Color LinkColor {
\r
128 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;
\r
129 if (template == null)
\r
130 throw new InvalidOperationException ("CellTemplate is null when getting this property.");
\r
131 return template.LinkColor;
\r
134 if (this.LinkColor == value)
\r
136 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;
\r
137 if (template == null)
\r
138 throw new InvalidOperationException ("CellTemplate is null when getting this property.");
\r
139 template.LinkColor = value;
\r
140 foreach (DataGridViewRow row in DataGridView.Rows)
\r
142 DataGridViewLinkCell cell = row.Cells[Index] as DataGridViewLinkCell;
\r
144 cell.LinkColor = value;
\r
146 DataGridView.InvalidateColumn (Index);
\r
149 [MonoInternalNote ("")]
\r
150 [DefaultValue ((string) null)]
\r
151 public string Text {
\r
153 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;
\r
154 if (template == null)
\r
155 throw new InvalidOperationException ("CellTemplate is null when getting this property.");
\r
159 if (this.Text == value)
\r
161 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;
\r
162 if (template == null)
\r
163 throw new InvalidOperationException ("CellTemplate is null when getting this property.");
\r
164 //TODO : sets the Text property of every cell in the column
\r
165 //TODO only if UseColumnTextForLinkValue is true
\r
167 DataGridView.InvalidateColumn (Index);
\r
171 //When TrackVisitedState is true, the VisitedLinkColor property value is used to display links that have already been visited.
\r
172 [DefaultValue (true)]
\r
173 public bool TrackVisitedState {
\r
175 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;
\r
176 if (template == null)
\r
177 throw new InvalidOperationException ("CellTemplate is null when getting this property.");
\r
178 return template.TrackVisitedState;
\r
181 if (this.TrackVisitedState == value)
\r
183 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;
\r
184 if (template == null)
\r
185 throw new InvalidOperationException ("CellTemplate is null when getting this property.");
\r
186 template.TrackVisitedState = value;
\r
187 foreach (DataGridViewRow row in DataGridView.Rows)
\r
189 DataGridViewLinkCell cell = row.Cells[Index] as DataGridViewLinkCell;
\r
191 cell.TrackVisitedState = value;
\r
193 DataGridView.InvalidateColumn (Index);
\r
197 // true if the Text property value is displayed as the link text; false if the cell FormattedValue property value is displayed as the link text. The default is false.
\r
198 [DefaultValue (false)]
\r
199 public bool UseColumnTextForLinkValue {
\r
201 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;
\r
202 if (template == null)
\r
203 throw new InvalidOperationException ("CellTemplate is null when getting this property.");
\r
204 return template.UseColumnTextForLinkValue;
\r
207 if (this.UseColumnTextForLinkValue == value)
\r
209 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;
\r
210 if (template == null)
\r
211 throw new InvalidOperationException ("CellTemplate is null when getting this property.");
\r
212 template.UseColumnTextForLinkValue = value;
\r
213 foreach (DataGridViewRow row in DataGridView.Rows)
\r
215 DataGridViewLinkCell cell = row.Cells[Index] as DataGridViewLinkCell;
\r
217 cell.UseColumnTextForLinkValue = value;
\r
219 DataGridView.InvalidateColumn (Index);
\r
223 //If the TrackVisitedState property is set to false, the VisitedLinkColor property is ignored.
\r
224 public Color VisitedLinkColor {
\r
226 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;
\r
227 if (template == null)
\r
228 throw new InvalidOperationException ("CellTemplate is null when getting this property.");
\r
229 return template.VisitedLinkColor;
\r
232 if (this.VisitedLinkColor == value)
\r
234 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;
\r
235 if (template == null)
\r
236 throw new InvalidOperationException ("CellTemplate is null when getting this property.");
\r
237 template.VisitedLinkColor = value;
\r
238 foreach (DataGridViewRow row in DataGridView.Rows)
\r
240 DataGridViewLinkCell cell = row.Cells[Index] as DataGridViewLinkCell;
\r
242 cell.VisitedLinkColor = value;
\r
244 DataGridView.InvalidateColumn (Index);
\r