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
30 using System.Collections.Generic;
\r
31 using System.ComponentModel;
\r
33 using System.Drawing;
\r
35 namespace System.Windows.Forms
\r
37 public class DataGridViewLinkColumn : DataGridViewColumn
\r
40 public DataGridViewLinkColumn ()
\r
42 base.CellTemplate = new DataGridViewLinkCell ();
\r
45 public override object Clone ()
\r
47 DataGridViewLinkColumn clone = (DataGridViewLinkColumn)base.Clone ();
\r
48 clone.CellTemplate = (DataGridViewCell) this.CellTemplate.Clone ();
\r
52 public override string ToString ()
\r
54 return base.ToString ();
\r
57 #region private fields
\r
59 private string text = string.Empty;
\r
63 #region Public Properties
\r
65 public Color ActiveLinkColor {
\r
67 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;
\r
68 if (template == null)
\r
69 throw new InvalidOperationException ("CellTemplate is null when getting this property.");
\r
70 return template.ActiveLinkColor;
\r
73 if (this.ActiveLinkColor == value)
\r
76 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;
\r
77 if (template == null)
\r
78 throw new InvalidOperationException ("CellTemplate is null when getting this property.");
\r
80 template.ActiveLinkColor = value;
\r
82 foreach (DataGridViewRow row in DataGridView.Rows) {
\r
83 DataGridViewLinkCell cell = row.Cells[Index] as DataGridViewLinkCell;
\r
85 cell.ActiveLinkColor = value;
\r
87 DataGridView.InvalidateColumn (Index);
\r
92 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
\r
94 public override DataGridViewCell CellTemplate {
\r
95 get { return base.CellTemplate; }
\r
96 set { base.CellTemplate = value as DataGridViewLinkCell; }
\r
100 [DefaultValue (LinkBehavior.SystemDefault)]
\r
101 public LinkBehavior LinkBehavior {
\r
103 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;
\r
104 if (template == null)
\r
105 throw new InvalidOperationException ("CellTemplate is null when getting this property.");
\r
106 return template.LinkBehavior;
\r
109 if (this.LinkBehavior == value)
\r
112 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;
\r
113 if (template == null)
\r
114 throw new InvalidOperationException ("CellTemplate is null when getting this property.");
\r
116 template.LinkBehavior = value;
\r
117 foreach (DataGridViewRow row in DataGridView.Rows)
\r
119 DataGridViewLinkCell cell = row.Cells[Index] as DataGridViewLinkCell;
\r
121 cell.LinkBehavior = value;
\r
123 DataGridView.InvalidateColumn (Index);
\r
127 public Color LinkColor {
\r
129 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;
\r
130 if (template == null)
\r
131 throw new InvalidOperationException ("CellTemplate is null when getting this property.");
\r
132 return template.LinkColor;
\r
135 if (this.LinkColor == value)
\r
137 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;
\r
138 if (template == null)
\r
139 throw new InvalidOperationException ("CellTemplate is null when getting this property.");
\r
140 template.LinkColor = value;
\r
141 foreach (DataGridViewRow row in DataGridView.Rows)
\r
143 DataGridViewLinkCell cell = row.Cells[Index] as DataGridViewLinkCell;
\r
145 cell.LinkColor = value;
\r
147 DataGridView.InvalidateColumn (Index);
\r
151 [DefaultValue ((string) null)]
\r
152 public string Text {
\r
154 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;
\r
155 if (template == null)
\r
156 throw new InvalidOperationException ("CellTemplate is null when getting this property.");
\r
160 if (this.Text == value)
\r
162 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;
\r
163 if (template == null)
\r
164 throw new InvalidOperationException ("CellTemplate is null when getting this property.");
\r
165 //TODO : sets the Text property of every cell in the column
\r
166 //TODO only if UseColumnTextForLinkValue is true
\r
168 DataGridView.InvalidateColumn (Index);
\r
172 //When TrackVisitedState is true, the VisitedLinkColor property value is used to display links that have already been visited.
\r
173 [DefaultValue (true)]
\r
174 public bool TrackVisitedState {
\r
176 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;
\r
177 if (template == null)
\r
178 throw new InvalidOperationException ("CellTemplate is null when getting this property.");
\r
179 return template.TrackVisitedState;
\r
182 if (this.TrackVisitedState == value)
\r
184 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;
\r
185 if (template == null)
\r
186 throw new InvalidOperationException ("CellTemplate is null when getting this property.");
\r
187 template.TrackVisitedState = value;
\r
188 foreach (DataGridViewRow row in DataGridView.Rows)
\r
190 DataGridViewLinkCell cell = row.Cells[Index] as DataGridViewLinkCell;
\r
192 cell.TrackVisitedState = value;
\r
194 DataGridView.InvalidateColumn (Index);
\r
198 // 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
199 [DefaultValue (false)]
\r
200 public bool UseColumnTextForLinkValue {
\r
202 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;
\r
203 if (template == null)
\r
204 throw new InvalidOperationException ("CellTemplate is null when getting this property.");
\r
205 return template.UseColumnTextForLinkValue;
\r
208 if (this.UseColumnTextForLinkValue == value)
\r
210 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;
\r
211 if (template == null)
\r
212 throw new InvalidOperationException ("CellTemplate is null when getting this property.");
\r
213 template.UseColumnTextForLinkValue = value;
\r
214 foreach (DataGridViewRow row in DataGridView.Rows)
\r
216 DataGridViewLinkCell cell = row.Cells[Index] as DataGridViewLinkCell;
\r
218 cell.UseColumnTextForLinkValue = value;
\r
220 DataGridView.InvalidateColumn (Index);
\r
224 //If the TrackVisitedState property is set to false, the VisitedLinkColor property is ignored.
\r
225 public Color VisitedLinkColor {
\r
227 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;
\r
228 if (template == null)
\r
229 throw new InvalidOperationException ("CellTemplate is null when getting this property.");
\r
230 return template.VisitedLinkColor;
\r
233 if (this.VisitedLinkColor == value)
\r
235 DataGridViewLinkCell template = CellTemplate as DataGridViewLinkCell;
\r
236 if (template == null)
\r
237 throw new InvalidOperationException ("CellTemplate is null when getting this property.");
\r
238 template.VisitedLinkColor = value;
\r
239 foreach (DataGridViewRow row in DataGridView.Rows)
\r
241 DataGridViewLinkCell cell = row.Cells[Index] as DataGridViewLinkCell;
\r
243 cell.VisitedLinkColor = value;
\r
245 DataGridView.InvalidateColumn (Index);
\r