1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
23 // Pedro MartÃnez Juliá <pedromj@gmail.com>
29 using System.Collections;
30 using System.ComponentModel;
32 using System.Windows.Forms;
34 using NUnit.Framework;
35 using System.Threading;
37 namespace MonoTests.System.Windows.Forms
40 public class DataGridViewCellTest : TestHelper
43 public void GetClipboardContentTest ()
45 DataGridViewClipboardCell cell = new DataGridViewClipboardCell ();
48 Assert.IsNull (cell.GetClipboardContentPublic (0, false, false, false, false, DataFormats.Text), "#01");
50 using (DataGridView dgv = new DataGridView ()) {
51 dgv.Columns.Add ("A", "A");
52 DataGridViewRow row = new DataGridViewRow ();
57 Assert.AreEqual ("abc\t", cell.GetClipboardContentPublic (0, false, false, false, false, DataFormats.Text), "#A1");
58 Assert.AreEqual ("abc\t", cell.GetClipboardContentPublic (0, false, false, false, false, DataFormats.UnicodeText), "#A2");
59 Assert.AreEqual ("<TD>abc</TD>", cell.GetClipboardContentPublic (0, false, false, false, false, DataFormats.Html), "#A3");
60 Assert.AreEqual ("abc,", cell.GetClipboardContentPublic (0, false, false, false, false, DataFormats.CommaSeparatedValue), "#A4");
62 Assert.AreEqual ("abc\t", cell.GetClipboardContentPublic (0, true, false, false, false, DataFormats.Text), "#A1");
63 Assert.AreEqual ("abc\t", cell.GetClipboardContentPublic (0, true, false, false, false, DataFormats.UnicodeText), "#A2");
64 Assert.AreEqual ("<TR><TD>abc</TD>", cell.GetClipboardContentPublic (0, true, false, false, false, DataFormats.Html), "#A3");
65 Assert.AreEqual ("abc,", cell.GetClipboardContentPublic (0, true, false, false, false, DataFormats.CommaSeparatedValue), "#A4");
67 Assert.AreEqual (string.Format("abc{0}", Environment.NewLine), cell.GetClipboardContentPublic (0, false, true, false, false, DataFormats.Text), "#A1");
68 Assert.AreEqual (string.Format ("abc{0}", Environment.NewLine), cell.GetClipboardContentPublic (0, false, true, false, false, DataFormats.UnicodeText), "#A2");
69 Assert.AreEqual ("<TD>abc</TD></TR>", cell.GetClipboardContentPublic (0, false, true, false, false, DataFormats.Html), "#A3");
70 Assert.AreEqual (string.Format ("abc{0}", Environment.NewLine), cell.GetClipboardContentPublic (0, false, true, false, false, DataFormats.CommaSeparatedValue), "#A4");
72 Assert.AreEqual ("abc\t", cell.GetClipboardContentPublic (0, false, false, true, false, DataFormats.Text), "#A1");
73 Assert.AreEqual ("abc\t", cell.GetClipboardContentPublic (0, false, false, true, false, DataFormats.UnicodeText), "#A2");
74 Assert.AreEqual ("<TD>abc</TD>", cell.GetClipboardContentPublic (0, false, false, true, false, DataFormats.Html), "#A3");
75 Assert.AreEqual ("abc,", cell.GetClipboardContentPublic (0, false, false, true, false, DataFormats.CommaSeparatedValue), "#A4");
77 Assert.AreEqual ("abc\t", cell.GetClipboardContentPublic (0, false, false, false, true, DataFormats.Text), "#A1");
78 Assert.AreEqual ("abc\t", cell.GetClipboardContentPublic (0, false, false, false, true, DataFormats.UnicodeText), "#A2");
79 Assert.AreEqual ("<TD>abc</TD>", cell.GetClipboardContentPublic (0, false, false, false, true, DataFormats.Html), "#A3");
80 Assert.AreEqual ("abc,", cell.GetClipboardContentPublic (0, false, false, false, true, DataFormats.CommaSeparatedValue), "#A4");
82 Assert.AreEqual ("abc", cell.GetClipboardContentPublic (0, true, true, true, true, DataFormats.Text), "#A1");
83 Assert.AreEqual ("abc", cell.GetClipboardContentPublic (0, true, true, true, true, DataFormats.UnicodeText), "#A2");
84 Assert.AreEqual ("<TABLE><TR><TD>abc</TD></TR></TABLE>", cell.GetClipboardContentPublic (0, true, true, true, true, DataFormats.Html), "#A3");
85 Assert.AreEqual ("abc", cell.GetClipboardContentPublic (0, true, true, true, true, DataFormats.CommaSeparatedValue), "#A4");
87 Assert.AreEqual ("abc", cell.GetClipboardContentPublic (0, false, true, true, true, DataFormats.Text), "#A1");
88 Assert.AreEqual ("abc", cell.GetClipboardContentPublic (0, false, true, true, true, DataFormats.UnicodeText), "#A2");
89 Assert.AreEqual ("<TD>abc</TD></TR></TABLE>", cell.GetClipboardContentPublic (0, false, true, true, true, DataFormats.Html), "#A3");
90 Assert.AreEqual ("abc", cell.GetClipboardContentPublic (0, false, true, true, true, DataFormats.CommaSeparatedValue), "#A4");
92 Assert.AreEqual ("abc\t", cell.GetClipboardContentPublic (0, true, false, true, true, DataFormats.Text), "#A1");
93 Assert.AreEqual ("abc\t", cell.GetClipboardContentPublic (0, true, false, true, true, DataFormats.UnicodeText), "#A2");
94 Assert.AreEqual ("<TABLE><TR><TD>abc</TD>", cell.GetClipboardContentPublic (0, true, false, true, true, DataFormats.Html), "#A3");
95 Assert.AreEqual ("abc,", cell.GetClipboardContentPublic (0, true, false, true, true, DataFormats.CommaSeparatedValue), "#A4");
97 Assert.AreEqual ("abc", cell.GetClipboardContentPublic (0, true, true, false, true, DataFormats.Text), "#A1");
98 Assert.AreEqual ("abc", cell.GetClipboardContentPublic (0, true, true, false, true, DataFormats.UnicodeText), "#A2");
99 Assert.AreEqual ("<TR><TD>abc</TD></TR></TABLE>", cell.GetClipboardContentPublic (0, true, true, false, true, DataFormats.Html), "#A3");
100 Assert.AreEqual ("abc", cell.GetClipboardContentPublic (0, true, true, false, true, DataFormats.CommaSeparatedValue), "#A4");
102 Assert.AreEqual ("abc" + Environment.NewLine, cell.GetClipboardContentPublic (0, true, true, true, false, DataFormats.Text), "#A1");
103 Assert.AreEqual ("abc" + Environment.NewLine, cell.GetClipboardContentPublic (0, true, true, true, false, DataFormats.UnicodeText), "#A2");
104 Assert.AreEqual ("<TABLE><TR><TD>abc</TD></TR>", cell.GetClipboardContentPublic (0, true, true, true, false, DataFormats.Html), "#A3");
105 Assert.AreEqual ("abc" + Environment.NewLine, cell.GetClipboardContentPublic (0, true, true, true, false, DataFormats.CommaSeparatedValue), "#A4");
107 cell.Selected = false;
109 Assert.AreEqual ("\t", cell.GetClipboardContentPublic (0, false, false, false, false, DataFormats.Text), "#A1");
110 Assert.AreEqual ("\t", cell.GetClipboardContentPublic (0, false, false, false, false, DataFormats.UnicodeText), "#A2");
111 Assert.AreEqual ("<TD> </TD>", cell.GetClipboardContentPublic (0, false, false, false, false, DataFormats.Html), "#A3");
112 Assert.AreEqual (",", cell.GetClipboardContentPublic (0, false, false, false, false, DataFormats.CommaSeparatedValue), "#A4");
114 Assert.AreEqual ("\t", cell.GetClipboardContentPublic (0, true, false, false, false, DataFormats.Text), "#A1");
115 Assert.AreEqual ("\t", cell.GetClipboardContentPublic (0, true, false, false, false, DataFormats.UnicodeText), "#A2");
116 Assert.AreEqual ("<TR><TD> </TD>", cell.GetClipboardContentPublic (0, true, false, false, false, DataFormats.Html), "#A3");
117 Assert.AreEqual (",", cell.GetClipboardContentPublic (0, true, false, false, false, DataFormats.CommaSeparatedValue), "#A4");
119 Assert.AreEqual (string.Format ("{0}", Environment.NewLine), cell.GetClipboardContentPublic (0, false, true, false, false, DataFormats.Text), "#A1");
120 Assert.AreEqual (string.Format ("{0}", Environment.NewLine), cell.GetClipboardContentPublic (0, false, true, false, false, DataFormats.UnicodeText), "#A2");
121 Assert.AreEqual ("<TD> </TD></TR>", cell.GetClipboardContentPublic (0, false, true, false, false, DataFormats.Html), "#A3");
122 Assert.AreEqual (string.Format ("{0}", Environment.NewLine), cell.GetClipboardContentPublic (0, false, true, false, false, DataFormats.CommaSeparatedValue), "#A4");
124 Assert.AreEqual ("\t", cell.GetClipboardContentPublic (0, false, false, true, false, DataFormats.Text), "#A1");
125 Assert.AreEqual ("\t", cell.GetClipboardContentPublic (0, false, false, true, false, DataFormats.UnicodeText), "#A2");
126 Assert.AreEqual ("<TD> </TD>", cell.GetClipboardContentPublic (0, false, false, true, false, DataFormats.Html), "#A3");
127 Assert.AreEqual (",", cell.GetClipboardContentPublic (0, false, false, true, false, DataFormats.CommaSeparatedValue), "#A4");
129 Assert.AreEqual ("\t", cell.GetClipboardContentPublic (0, false, false, false, true, DataFormats.Text), "#A1");
130 Assert.AreEqual ("\t", cell.GetClipboardContentPublic (0, false, false, false, true, DataFormats.UnicodeText), "#A2");
131 Assert.AreEqual ("<TD> </TD>", cell.GetClipboardContentPublic (0, false, false, false, true, DataFormats.Html), "#A3");
132 Assert.AreEqual (",", cell.GetClipboardContentPublic (0, false, false, false, true, DataFormats.CommaSeparatedValue), "#A4");
134 Assert.AreEqual ("", cell.GetClipboardContentPublic (0, true, true, true, true, DataFormats.Text), "#A1");
135 Assert.AreEqual ("", cell.GetClipboardContentPublic (0, true, true, true, true, DataFormats.UnicodeText), "#A2");
136 Assert.AreEqual ("<TABLE><TR><TD> </TD></TR></TABLE>", cell.GetClipboardContentPublic (0, true, true, true, true, DataFormats.Html), "#A3");
137 Assert.AreEqual ("", cell.GetClipboardContentPublic (0, true, true, true, true, DataFormats.CommaSeparatedValue), "#A4");
139 Assert.AreEqual ("", cell.GetClipboardContentPublic (0, false, true, true, true, DataFormats.Text), "#A1");
140 Assert.AreEqual ("", cell.GetClipboardContentPublic (0, false, true, true, true, DataFormats.UnicodeText), "#A2");
141 Assert.AreEqual ("<TD> </TD></TR></TABLE>", cell.GetClipboardContentPublic (0, false, true, true, true, DataFormats.Html), "#A3");
142 Assert.AreEqual ("", cell.GetClipboardContentPublic (0, false, true, true, true, DataFormats.CommaSeparatedValue), "#A4");
144 Assert.AreEqual ("\t", cell.GetClipboardContentPublic (0, true, false, true, true, DataFormats.Text), "#A1");
145 Assert.AreEqual ("\t", cell.GetClipboardContentPublic (0, true, false, true, true, DataFormats.UnicodeText), "#A2");
146 Assert.AreEqual ("<TABLE><TR><TD> </TD>", cell.GetClipboardContentPublic (0, true, false, true, true, DataFormats.Html), "#A3");
147 Assert.AreEqual (",", cell.GetClipboardContentPublic (0, true, false, true, true, DataFormats.CommaSeparatedValue), "#A4");
149 Assert.AreEqual ("", cell.GetClipboardContentPublic (0, true, true, false, true, DataFormats.Text), "#A1");
150 Assert.AreEqual ("", cell.GetClipboardContentPublic (0, true, true, false, true, DataFormats.UnicodeText), "#A2");
151 Assert.AreEqual ("<TR><TD> </TD></TR></TABLE>", cell.GetClipboardContentPublic (0, true, true, false, true, DataFormats.Html), "#A3");
152 Assert.AreEqual ("", cell.GetClipboardContentPublic (0, true, true, false, true, DataFormats.CommaSeparatedValue), "#A4");
154 Assert.AreEqual ("" + Environment.NewLine, cell.GetClipboardContentPublic (0, true, true, true, false, DataFormats.Text), "#A1");
155 Assert.AreEqual ("" + Environment.NewLine, cell.GetClipboardContentPublic (0, true, true, true, false, DataFormats.UnicodeText), "#A2");
156 Assert.AreEqual ("<TABLE><TR><TD> </TD></TR>", cell.GetClipboardContentPublic (0, true, true, true, false, DataFormats.Html), "#A3");
157 Assert.AreEqual ("" + Environment.NewLine, cell.GetClipboardContentPublic (0, true, true, true, false, DataFormats.CommaSeparatedValue), "#A4");
162 [ExpectedException (typeof (ArgumentOutOfRangeException))]
163 public void GetClipboardContentTestException ()
165 DataGridViewClipboardCell cell = new DataGridViewClipboardCell ();
168 Assert.IsNull (cell.GetClipboardContentPublic (0, false, false, false, false, DataFormats.Text), "#01");
170 using (DataGridView dgv = new DataGridView ()) {
171 dgv.Columns.Add ("A", "A");
172 DataGridViewRow row = new DataGridViewRow ();
173 row.Cells.Add (cell);
175 cell.Selected = true;
177 Assert.AreEqual ("abc\t", cell.GetClipboardContentPublic (123, false, false, false, false, DataFormats.Text), "#A1");
178 Assert.AreEqual ("abc\t", cell.GetClipboardContentPublic (123, false, false, false, false, DataFormats.UnicodeText), "#A2");
179 Assert.AreEqual ("<TD>abc</TD>", cell.GetClipboardContentPublic (123, false, false, false, false, DataFormats.Html), "#A3");
180 Assert.AreEqual ("abc,", cell.GetClipboardContentPublic (123, false, false, false, false, DataFormats.CommaSeparatedValue), "#A4");
185 public void ReadOnlyTest ()
187 using (DataGridView dgv = DataGridViewCommon.CreateAndFill ()) {
188 Assert.IsFalse (dgv.ReadOnly, "1-DGV");
189 Assert.IsFalse (dgv.Rows [0].ReadOnly, "1-R0");
190 Assert.IsFalse (dgv.Rows [1].ReadOnly, "1-R1");
191 Assert.IsFalse (dgv.Columns [0].ReadOnly, "1-C1");
192 Assert.IsFalse (dgv.Columns [1].ReadOnly, "1-C1");
193 Assert.IsFalse (dgv [0, 0].ReadOnly, "1-C00");
194 Assert.IsFalse (dgv [1, 0].ReadOnly, "1-C10");
195 Assert.IsFalse (dgv [0, 1].ReadOnly, "1-C01");
196 Assert.IsFalse (dgv [1, 1].ReadOnly, "1-C11");
200 using (DataGridView dgv = DataGridViewCommon.CreateAndFill ()) {
202 Assert.IsTrue (dgv.ReadOnly, "2-DGV");
203 Assert.IsTrue (dgv.Rows [0].ReadOnly, "2-R0");
204 Assert.IsTrue (dgv.Rows [1].ReadOnly, "2-R1");
205 Assert.IsTrue (dgv.Columns [0].ReadOnly, "2-C1");
206 Assert.IsTrue (dgv.Columns [1].ReadOnly, "2-C1");
207 Assert.IsTrue (dgv [0, 0].ReadOnly, "2-C00");
208 Assert.IsTrue (dgv [1, 0].ReadOnly, "2-C10");
209 Assert.IsTrue (dgv [0, 1].ReadOnly, "2-C01");
210 Assert.IsTrue (dgv [1, 1].ReadOnly, "2-C11");
213 // If the DGV is ReadOnly, everything is ReadOnly.
214 using (DataGridView dgv = DataGridViewCommon.CreateAndFill ()) {
216 Assert.IsTrue (dgv.ReadOnly, "3-DGV");
217 dgv.Rows [0].ReadOnly = false;
218 Assert.IsTrue (dgv.Rows [0].ReadOnly, "3-R0");
219 Assert.IsTrue (dgv.Rows [1].ReadOnly, "3-R1");
220 dgv.Columns [0].ReadOnly = false;
221 Assert.IsTrue (dgv.Columns [0].ReadOnly, "3-C1");
222 Assert.IsTrue (dgv.Columns [1].ReadOnly, "3-C1");
223 dgv [0, 0].ReadOnly = false;
224 Assert.IsTrue (dgv [0, 0].ReadOnly, "3-C00");
225 Assert.IsTrue (dgv [1, 0].ReadOnly, "3-C10");
226 Assert.IsTrue (dgv [0, 1].ReadOnly, "3-C01");
227 Assert.IsTrue (dgv [1, 1].ReadOnly, "3-C11");
230 using (DataGridView dgv = DataGridViewCommon.CreateAndFill ()) {
231 Assert.IsFalse (dgv.ReadOnly, "4-DGV");
232 dgv.Rows [0].ReadOnly = true;
233 Assert.IsTrue (dgv.Rows [0].ReadOnly, "4-R0");
234 Assert.IsFalse (dgv.Rows [1].ReadOnly, "4-R1");
235 dgv.Columns [0].ReadOnly = true;
236 Assert.IsTrue (dgv.Columns [0].ReadOnly, "4-C1");
237 Assert.IsFalse (dgv.Columns [1].ReadOnly, "4-C1");
238 Assert.IsTrue (dgv [0, 0].ReadOnly, "4-C00");
239 Assert.IsTrue (dgv [1, 0].ReadOnly, "4-C10");
240 Assert.IsTrue (dgv [0, 1].ReadOnly, "4-C01");
241 Assert.IsFalse (dgv [1, 1].ReadOnly, "4-C11");
244 using (DataGridView dgv = DataGridViewCommon.CreateAndFill ()) {
245 Assert.IsFalse (dgv.ReadOnly, "5-DGV");
246 dgv.Rows [0].ReadOnly = true;
247 Assert.IsTrue (dgv.Rows [0].ReadOnly, "5-R0");
248 Assert.IsFalse (dgv.Rows [1].ReadOnly, "5-R1");
249 dgv.Columns [0].ReadOnly = true;
250 Assert.IsTrue (dgv.Columns [0].ReadOnly, "5-C1");
251 Assert.IsFalse (dgv.Columns [1].ReadOnly, "5-C1");
252 dgv [0, 0].ReadOnly = false; // Cell override
253 Assert.IsFalse (dgv [0, 0].ReadOnly, "5-C00");
254 Assert.IsTrue (dgv [1, 0].ReadOnly, "5-C10");
255 Assert.IsTrue (dgv [0, 1].ReadOnly, "5-C01");
256 Assert.IsFalse (dgv [1, 1].ReadOnly, "5-C11");
261 public void EditTypeTest ()
263 DataGridViewCell cell =new DataGridViewCellMockObject ();
264 Assert.AreEqual ("DataGridViewTextBoxEditingControl", cell.EditType.Name, "#01");
268 public void TestDefaultValues ()
270 DataGridViewCell cell = new DataGridViewCellMockObject ();
272 Assert.IsNotNull (cell.AccessibilityObject, "#cell.AccessibilityObject");
273 Assert.AreEqual (-1, cell.ColumnIndex, "#cell.ColumnIndex");
274 Assert.IsNotNull (cell.ContentBounds, "#cell.ContentBounds");
275 Assert.IsNull (cell.ContextMenuStrip, "#cell.ContextMenuStrip");
276 Assert.IsNull (cell.DataGridView, "#cell.DataGridView");
277 Assert.IsNull (cell.DefaultNewRowValue, "#cell.DefaultNewRowValue");
278 Assert.AreEqual (false, cell.Displayed, "#cell.Displayed");
279 Assert.IsNull (cell.EditedFormattedValue, "#cell.EditedFormattedValue");
280 Assert.IsNotNull (cell.EditType, "#cell.EditType");
282 object zxf = cell.ErrorIconBounds;
283 TestHelper.RemoveWarning (zxf);
284 Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#cell.ErrorIconBounds");
285 } catch (InvalidOperationException ex) {
286 // We don't need to check the specific message
287 //Assert.AreEqual (@"Cell is not in a DataGridView. The cell cannot retrieve the inherited cell style.", ex.Message);
288 } catch (Exception ex) {
289 Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#cell.ErrorIconBounds");
291 Assert.AreEqual (@"", cell.ErrorText, "#cell.ErrorText");
292 Assert.IsNull (cell.FormattedValue, "#cell.FormattedValue");
293 Assert.IsNull (cell.FormattedValueType, "#cell.FormattedValueType");
294 Assert.AreEqual (false, cell.Frozen, "#cell.Frozen");
295 Assert.AreEqual (false, cell.HasStyle, "#cell.HasStyle");
296 Assert.AreEqual (DataGridViewElementStates.ResizableSet, cell.InheritedState, "#cell.InheritedState");
298 object zxf = cell.InheritedStyle;
299 TestHelper.RemoveWarning (zxf);
300 Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#cell.InheritedStyle");
301 } catch (InvalidOperationException ex) {
302 Assert.AreEqual (@"Cell is not in a DataGridView. The cell cannot retrieve the inherited cell style.", ex.Message);
303 } catch (Exception ex) {
304 Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#cell.InheritedStyle");
306 Assert.AreEqual (false, cell.IsInEditMode, "#cell.IsInEditMode");
307 Assert.IsNull (cell.OwningColumn, "#cell.OwningColumn");
308 Assert.IsNull (cell.OwningRow, "#cell.OwningRow");
309 Assert.IsNotNull (cell.PreferredSize, "#cell.PreferredSize");
310 Assert.AreEqual (false, cell.ReadOnly, "#cell.ReadOnly");
311 Assert.AreEqual (false, cell.Resizable, "#cell.Resizable");
312 Assert.AreEqual (-1, cell.RowIndex, "#cell.RowIndex");
313 Assert.AreEqual (false, cell.Selected, "#cell.Selected");
314 Assert.IsNotNull (cell.Size, "#cell.Size");
315 Assert.AreEqual (DataGridViewElementStates.None, cell.State, "#cell.State");
316 Assert.IsNotNull (cell.Style, "#cell.Style");
317 Assert.IsNull (cell.Tag, "#cell.Tag");
318 Assert.AreEqual (@"", cell.ToolTipText, "#cell.ToolTipText");
319 Assert.IsNull (cell.Value, "#cell.Value");
320 Assert.IsNull (cell.ValueType, "#cell.ValueType");
321 Assert.AreEqual (false, cell.Visible, "#cell.Visible");
325 [NUnit.Framework.Category ("NotWorking")] // DGVComboBox not implemented
326 public void AddRow_Changes ()
328 using (DataGridView dgv = new DataGridView ()) {
329 DataGridViewColumn col = new DataGridViewComboBoxColumn ();
330 DataGridViewRow row = new DataGridViewRow ();
331 DataGridViewCell cell = new DataGridViewComboBoxCell ();
333 Assert.IsNotNull (cell.AccessibilityObject, "#A cell.AccessibilityObject");
334 Assert.AreEqual (-1, cell.ColumnIndex, "#A cell.ColumnIndex");
335 Assert.IsNotNull (cell.ContentBounds, "#A cell.ContentBounds");
336 Assert.IsNull (cell.ContextMenuStrip, "#A cell.ContextMenuStrip");
337 Assert.IsNull (cell.DataGridView, "#A cell.DataGridView");
338 Assert.IsNull (cell.DefaultNewRowValue, "#A cell.DefaultNewRowValue");
339 Assert.AreEqual (false, cell.Displayed, "#A cell.Displayed");
340 Assert.IsNull (cell.EditedFormattedValue, "#A cell.EditedFormattedValue");
341 Assert.IsNotNull (cell.EditType, "#A cell.EditType");
343 object zxf = cell.ErrorIconBounds;
344 TestHelper.RemoveWarning (zxf);
345 Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#A cell.ErrorIconBounds");
346 } catch (InvalidOperationException ex) {
347 //Assert.AreEqual (@"Cell is not in a DataGridView. The cell cannot retrieve the inherited cell style.", ex.Message);
348 } catch (Exception ex) {
349 Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#A cell.ErrorIconBounds");
351 Assert.AreEqual (@"", cell.ErrorText, "#A cell.ErrorText");
352 Assert.IsNull (cell.FormattedValue, "#A cell.FormattedValue");
353 Assert.IsNotNull (cell.FormattedValueType, "#A cell.FormattedValueType");
354 Assert.AreEqual (false, cell.Frozen, "#A cell.Frozen");
355 Assert.AreEqual (false, cell.HasStyle, "#A cell.HasStyle");
356 Assert.AreEqual (DataGridViewElementStates.ResizableSet, cell.InheritedState, "#A cell.InheritedState");
358 object zxf = cell.InheritedStyle;
359 TestHelper.RemoveWarning (zxf);
360 Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#A cell.InheritedStyle");
361 } catch (InvalidOperationException ex) {
362 Assert.AreEqual (@"Cell is not in a DataGridView. The cell cannot retrieve the inherited cell style.", ex.Message);
363 } catch (Exception ex) {
364 Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#A cell.InheritedStyle");
366 Assert.AreEqual (false, cell.IsInEditMode, "#A cell.IsInEditMode");
367 Assert.IsNull (cell.OwningColumn, "#A cell.OwningColumn");
368 Assert.IsNull (cell.OwningRow, "#A cell.OwningRow");
369 Assert.IsNotNull (cell.PreferredSize, "#A cell.PreferredSize");
370 Assert.AreEqual (false, cell.ReadOnly, "#A cell.ReadOnly");
371 Assert.AreEqual (false, cell.Resizable, "#A cell.Resizable");
372 Assert.AreEqual (-1, cell.RowIndex, "#A cell.RowIndex");
373 Assert.AreEqual (false, cell.Selected, "#A cell.Selected");
374 Assert.IsNotNull (cell.Size, "#A cell.Size");
375 Assert.AreEqual (DataGridViewElementStates.None, cell.State, "#A cell.State");
377 Assert.IsNotNull (cell.Style, "#A cell.Style");
378 Assert.IsNull (cell.Tag, "#A cell.Tag");
379 Assert.AreEqual (@"", cell.ToolTipText, "#A cell.ToolTipText");
380 Assert.IsNull (cell.Value, "#A cell.Value");
381 Assert.IsNotNull (cell.ValueType, "#A cell.ValueType");
382 Assert.AreEqual (false, cell.Visible, "#A cell.Visible");
384 row.Cells.Add (cell);
386 Assert.IsNotNull (cell.AccessibilityObject, "#B cell.AccessibilityObject");
387 Assert.AreEqual (-1, cell.ColumnIndex, "#B cell.ColumnIndex");
388 Assert.IsNotNull (cell.ContentBounds, "#B cell.ContentBounds");
389 Assert.IsNull (cell.ContextMenuStrip, "#B cell.ContextMenuStrip");
390 Assert.IsNull (cell.DataGridView, "#B cell.DataGridView");
391 Assert.IsNull (cell.DefaultNewRowValue, "#B cell.DefaultNewRowValue");
392 Assert.AreEqual (false, cell.Displayed, "#B cell.Displayed");
393 Assert.IsNull (cell.EditedFormattedValue, "#B cell.EditedFormattedValue");
394 Assert.IsNotNull (cell.EditType, "#B cell.EditType");
396 object zxf = cell.ErrorIconBounds;
397 TestHelper.RemoveWarning (zxf);
398 Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#B cell.ErrorIconBounds");
399 } catch (InvalidOperationException ex) {
400 //Assert.AreEqual (@"Cell is not in a DataGridView. The cell cannot retrieve the inherited cell style.", ex.Message);
401 } catch (Exception ex) {
402 Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#B cell.ErrorIconBounds");
404 Assert.AreEqual (@"", cell.ErrorText, "#B cell.ErrorText");
405 Assert.IsNull (cell.FormattedValue, "#B cell.FormattedValue");
406 Assert.IsNotNull (cell.FormattedValueType, "#B cell.FormattedValueType");
407 Assert.AreEqual (false, cell.Frozen, "#B cell.Frozen");
408 Assert.AreEqual (false, cell.HasStyle, "#B cell.HasStyle");
409 Assert.AreEqual (DataGridViewElementStates.ResizableSet | DataGridViewElementStates.Visible, cell.InheritedState, "#B cell.InheritedState");
411 object zxf = cell.InheritedStyle;
412 TestHelper.RemoveWarning (zxf);
413 Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#B cell.InheritedStyle");
414 } catch (InvalidOperationException ex) {
415 Assert.AreEqual (@"Cell is not in a DataGridView. The cell cannot retrieve the inherited cell style.", ex.Message);
416 } catch (Exception ex) {
417 Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#B cell.InheritedStyle");
419 Assert.AreEqual (false, cell.IsInEditMode, "#B cell.IsInEditMode");
420 Assert.IsNull (cell.OwningColumn, "#B cell.OwningColumn");
421 Assert.IsNotNull (cell.OwningRow, "#B cell.OwningRow");
422 Assert.IsNotNull (cell.PreferredSize, "#B cell.PreferredSize");
423 Assert.AreEqual (false, cell.ReadOnly, "#B cell.ReadOnly");
424 Assert.AreEqual (false, cell.Resizable, "#B cell.Resizable");
425 Assert.AreEqual (-1, cell.RowIndex, "#B cell.RowIndex");
426 Assert.AreEqual (false, cell.Selected, "#B cell.Selected");
427 Assert.IsNotNull (cell.Size, "#B cell.Size");
428 Assert.AreEqual (DataGridViewElementStates.None, cell.State, "#B cell.State");
430 Assert.IsNotNull (cell.Style, "#B cell.Style");
431 Assert.IsNull (cell.Tag, "#B cell.Tag");
432 Assert.AreEqual (@"", cell.ToolTipText, "#B cell.ToolTipText");
433 Assert.IsNull (cell.Value, "#B cell.Value");
434 Assert.IsNotNull (cell.ValueType, "#B cell.ValueType");
435 Assert.AreEqual (true, cell.Visible, "#B cell.Visible");
437 dgv.Columns.Add (col);
439 Assert.IsNotNull (cell.AccessibilityObject, "#C cell.AccessibilityObject");
440 Assert.AreEqual (-1, cell.ColumnIndex, "#C cell.ColumnIndex");
441 Assert.IsNotNull (cell.ContentBounds, "#C cell.ContentBounds");
442 Assert.IsNull (cell.ContextMenuStrip, "#C cell.ContextMenuStrip");
443 Assert.IsNull (cell.DataGridView, "#C cell.DataGridView");
444 Assert.IsNull (cell.DefaultNewRowValue, "#C cell.DefaultNewRowValue");
445 Assert.AreEqual (false, cell.Displayed, "#C cell.Displayed");
446 Assert.IsNull (cell.EditedFormattedValue, "#C cell.EditedFormattedValue");
447 Assert.IsNotNull (cell.EditType, "#C cell.EditType");
449 object zxf = cell.ErrorIconBounds;
450 TestHelper.RemoveWarning (zxf);
451 Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#C cell.ErrorIconBounds");
452 } catch (InvalidOperationException ex) {
453 //Assert.AreEqual (@"Cell is not in a DataGridView. The cell cannot retrieve the inherited cell style.", ex.Message);
454 } catch (Exception ex) {
455 Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#C cell.ErrorIconBounds");
457 Assert.AreEqual (@"", cell.ErrorText, "#C cell.ErrorText");
458 Assert.IsNull (cell.FormattedValue, "#C cell.FormattedValue");
459 Assert.IsNotNull (cell.FormattedValueType, "#C cell.FormattedValueType");
460 Assert.AreEqual (false, cell.Frozen, "#C cell.Frozen");
461 Assert.AreEqual (false, cell.HasStyle, "#C cell.HasStyle");
462 Assert.AreEqual (DataGridViewElementStates.ResizableSet | DataGridViewElementStates.Visible, cell.InheritedState, "#C cell.InheritedState");
464 object zxf = cell.InheritedStyle;
465 TestHelper.RemoveWarning (zxf);
466 Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#C cell.InheritedStyle");
467 } catch (InvalidOperationException ex) {
468 Assert.AreEqual (@"Cell is not in a DataGridView. The cell cannot retrieve the inherited cell style.", ex.Message);
469 } catch (Exception ex) {
470 Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#C cell.InheritedStyle");
472 Assert.AreEqual (false, cell.IsInEditMode, "#C cell.IsInEditMode");
473 Assert.IsNull (cell.OwningColumn, "#C cell.OwningColumn");
474 Assert.IsNotNull (cell.OwningRow, "#C cell.OwningRow");
475 Assert.IsNotNull (cell.PreferredSize, "#C cell.PreferredSize");
476 Assert.AreEqual (false, cell.ReadOnly, "#C cell.ReadOnly");
477 Assert.AreEqual (false, cell.Resizable, "#C cell.Resizable");
478 Assert.AreEqual (-1, cell.RowIndex, "#C cell.RowIndex");
479 Assert.AreEqual (false, cell.Selected, "#C cell.Selected");
480 Assert.IsNotNull (cell.Size, "#C cell.Size");
481 Assert.AreEqual (DataGridViewElementStates.None, cell.State, "#C cell.State");
483 Assert.IsNotNull (cell.Style, "#C cell.Style");
484 Assert.IsNull (cell.Tag, "#C cell.Tag");
485 Assert.AreEqual (@"", cell.ToolTipText, "#C cell.ToolTipText");
486 Assert.IsNull (cell.Value, "#C cell.Value");
487 Assert.IsNotNull (cell.ValueType, "#C cell.ValueType");
488 Assert.AreEqual (true, cell.Visible, "#C cell.Visible");
492 Assert.IsNotNull (cell.AccessibilityObject, "#D cell.AccessibilityObject");
493 Assert.AreEqual (0, cell.ColumnIndex, "#D cell.ColumnIndex");
495 object zxf = cell.ContentBounds;
496 TestHelper.RemoveWarning (zxf);
497 Assert.Fail ("Expected 'System.ArgumentOutOfRangeException', but no exception was thrown.", "#D cell.ContentBounds");
498 } catch (ArgumentOutOfRangeException ex) {
499 Assert.AreEqual (string.Format (@"Specified argument was out of the range of valid values.{0}Parameter name: rowIndex", Environment.NewLine), ex.Message);
500 } catch (Exception ex) {
501 Assert.Fail ("Expected 'System.ArgumentOutOfRangeException', got '" + ex.GetType ().FullName + "'.", "#D cell.ContentBounds");
503 Assert.IsNull (cell.ContextMenuStrip, "#D cell.ContextMenuStrip");
504 Assert.IsNotNull (cell.DataGridView, "#D cell.DataGridView");
505 Assert.IsNull (cell.DefaultNewRowValue, "#D cell.DefaultNewRowValue");
506 Assert.AreEqual (false, cell.Displayed, "#D cell.Displayed");
508 object zxf = cell.EditedFormattedValue;
509 TestHelper.RemoveWarning (zxf);
510 Assert.Fail ("Expected 'System.ArgumentOutOfRangeException', but no exception was thrown.", "#D cell.EditedFormattedValue");
511 } catch (ArgumentOutOfRangeException ex) {
512 Assert.AreEqual (string.Format (@"Specified argument was out of the range of valid values.{0}Parameter name: rowIndex", Environment.NewLine), ex.Message);
513 } catch (Exception ex) {
514 Assert.Fail ("Expected 'System.ArgumentOutOfRangeException', got '" + ex.GetType ().FullName + "'.", "#D cell.EditedFormattedValue");
516 Assert.IsNotNull (cell.EditType, "#D cell.EditType");
518 object zxf = cell.ErrorIconBounds;
519 TestHelper.RemoveWarning (zxf);
520 Assert.Fail ("Expected 'System.ArgumentOutOfRangeException', but no exception was thrown.", "#D cell.ErrorIconBounds");
521 } catch (ArgumentOutOfRangeException ex) {
522 //Assert.AreEqual (string.Format (@"Specified argument was out of the range of valid values.{0}Parameter name: rowIndex", Environment.NewLine), ex.Message);
523 } catch (Exception ex) {
524 Assert.Fail ("Expected 'System.ArgumentOutOfRangeException', got '" + ex.GetType ().FullName + "'.", "#D cell.ErrorIconBounds");
526 Assert.AreEqual (@"", cell.ErrorText, "#D cell.ErrorText");
528 object zxf = cell.FormattedValue;
529 TestHelper.RemoveWarning (zxf);
530 Assert.Fail ("Expected 'System.ArgumentOutOfRangeException', but no exception was thrown.", "#D cell.FormattedValue");
531 } catch (ArgumentOutOfRangeException ex) {
532 Assert.AreEqual (string.Format (@"Specified argument was out of the range of valid values.{0}Parameter name: rowIndex", Environment.NewLine), ex.Message);
533 } catch (Exception ex) {
534 Assert.Fail ("Expected 'System.ArgumentOutOfRangeException', got '" + ex.GetType ().FullName + "'.", "#D cell.FormattedValue");
536 Assert.IsNotNull (cell.FormattedValueType, "#D cell.FormattedValueType");
537 Assert.AreEqual (false, cell.Frozen, "#D cell.Frozen");
538 Assert.AreEqual (false, cell.HasStyle, "#D cell.HasStyle");
540 object zxf = cell.InheritedState;
541 TestHelper.RemoveWarning (zxf);
542 Assert.Fail ("Expected 'System.ArgumentOutOfRangeException', but no exception was thrown.", "#D cell.InheritedState");
543 } catch (ArgumentOutOfRangeException ex) {
544 Assert.AreEqual (string.Format (@"Specified argument was out of the range of valid values.{0}Parameter name: rowIndex", Environment.NewLine), ex.Message);
545 } catch (Exception ex) {
546 Assert.Fail ("Expected 'System.ArgumentOutOfRangeException', got '" + ex.GetType ().FullName + "'.", "#D cell.InheritedState");
549 object zxf = cell.InheritedStyle;
550 TestHelper.RemoveWarning (zxf);
551 Assert.Fail ("Expected 'System.ArgumentOutOfRangeException', but no exception was thrown.", "#D cell.InheritedStyle");
552 } catch (ArgumentOutOfRangeException ex) {
553 Assert.AreEqual (string.Format (@"Specified argument was out of the range of valid values.{0}Parameter name: rowIndex", Environment.NewLine), ex.Message);
554 } catch (Exception ex) {
555 Assert.Fail ("Expected 'System.ArgumentOutOfRangeException', got '" + ex.GetType ().FullName + "'.", "#D cell.InheritedStyle");
558 object zxf = cell.IsInEditMode;
559 TestHelper.RemoveWarning (zxf);
560 Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#D cell.IsInEditMode");
561 } catch (InvalidOperationException ex) {
562 Assert.AreEqual (@"Operation cannot be performed on a cell of a shared row.", ex.Message);
563 } catch (Exception ex) {
564 Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#D cell.IsInEditMode");
566 Assert.IsNotNull (cell.OwningColumn, "#D cell.OwningColumn");
567 Assert.IsNotNull (cell.OwningRow, "#D cell.OwningRow");
569 object zxf = cell.PreferredSize;
570 TestHelper.RemoveWarning (zxf);
571 Assert.Fail ("Expected 'System.ArgumentOutOfRangeException', but no exception was thrown.", "#D cell.PreferredSize");
572 } catch (ArgumentOutOfRangeException ex) {
573 Assert.AreEqual (string.Format (@"Specified argument was out of the range of valid values.{0}Parameter name: rowIndex", Environment.NewLine), ex.Message);
574 } catch (Exception ex) {
575 Assert.Fail ("Expected 'System.ArgumentOutOfRangeException', got '" + ex.GetType ().FullName + "'.", "#D cell.PreferredSize");
577 Assert.AreEqual (false, cell.ReadOnly, "#D cell.ReadOnly");
578 Assert.AreEqual (false, cell.Resizable, "#D cell.Resizable");
579 Assert.AreEqual (-1, cell.RowIndex, "#D cell.RowIndex");
580 Assert.AreEqual (false, cell.Selected, "#D cell.Selected");
582 object zxf = cell.Size;
583 TestHelper.RemoveWarning (zxf);
584 Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#D cell.Size");
585 } catch (InvalidOperationException ex) {
586 Assert.AreEqual (@"Getting the Size property of a cell in a shared row is not a valid operation.", ex.Message);
587 } catch (Exception ex) {
588 Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#D cell.Size");
590 Assert.AreEqual (DataGridViewElementStates.None, cell.State, "#D cell.State");
592 Assert.IsNotNull (cell.Style, "#D cell.Style");
593 Assert.IsNull (cell.Tag, "#D cell.Tag");
594 Assert.AreEqual (@"", cell.ToolTipText, "#D cell.ToolTipText");
596 object zxf = cell.Value;
597 TestHelper.RemoveWarning (zxf);
598 Assert.Fail ("Expected 'System.ArgumentOutOfRangeException', but no exception was thrown.", "#D cell.Value");
599 } catch (ArgumentOutOfRangeException ex) {
600 Assert.AreEqual (string.Format (@"Specified argument was out of the range of valid values.{0}Parameter name: rowIndex", Environment.NewLine), ex.Message);
601 } catch (Exception ex) {
602 Assert.Fail ("Expected 'System.ArgumentOutOfRangeException', got '" + ex.GetType ().FullName + "'.", "#D cell.Value");
604 Assert.IsNotNull (cell.ValueType, "#D cell.ValueType");
605 Assert.AreEqual (false, cell.Visible, "#D cell.Visible");
611 [ExpectedException(typeof(Exception))]
612 public void TestException () {
613 ConcreteCollection myCollection;
614 myCollection = new ConcreteCollection();
616 AssertEquals ("#UniqueID", expected, actual);
623 public void ColumnIndex ()
625 DataGridViewCell c = new BaseCell ();
626 Assert.AreEqual (-1, c.ColumnIndex, "A1");
628 DataGridView dgv = new DataGridView ();
629 dgv.Columns.Add ("hi", "there");
631 DataGridViewRow row = new DataGridViewRow ();
635 Assert.AreEqual (0, dgv.Rows[0].Cells[0].ColumnIndex, "A2");
639 public void ContentBounds ()
641 DataGridViewCell c = new BaseCell ();
642 Assert.AreEqual (Rectangle.Empty, c.ContentBounds, "A1");
644 DataGridView dgv = new DataGridView ();
645 dgv.Columns.Add ("hi", "there");
647 DataGridViewRow row = new DataGridViewRow ();
651 Assert.AreEqual (Rectangle.Empty, dgv.Rows[0].Cells[0].ContentBounds, "A2");
655 public void ContextMenuStrip ()
657 DataGridViewCell c = new BaseCell ();
658 Assert.AreEqual (null, c.ContextMenuStrip, "A1");
660 DataGridView dgv = new DataGridView ();
661 dgv.Columns.Add ("hi", "there");
663 DataGridViewRow row = new DataGridViewRow ();
667 ContextMenuStrip cms1 = new ContextMenuStrip ();
668 cms1.Items.Add ("hey");
670 ContextMenuStrip cms2 = new ContextMenuStrip ();
671 cms2.Items.Add ("yo");
673 dgv.Rows[0].ContextMenuStrip = cms1;
674 Assert.AreEqual (null, dgv.Rows[0].Cells[0].ContextMenuStrip, "A2");
676 dgv.Rows[0].Cells[0].ContextMenuStrip = cms2;
677 Assert.AreSame (cms2, dgv.Rows[0].Cells[0].ContextMenuStrip, "A3");
681 public void DataGridView ()
683 DataGridViewCell c = new BaseCell ();
684 Assert.AreEqual (null, c.DataGridView, "A1");
686 DataGridView dgv = new DataGridView ();
687 dgv.Columns.Add ("hi", "there");
689 DataGridViewRow row = new DataGridViewRow ();
693 Assert.AreSame (dgv, dgv.Rows[0].Cells[0].DataGridView, "A2");
697 public void DefaultNewRowValue ()
699 DataGridViewCell c = new BaseCell ();
700 Assert.AreEqual (null, c.DefaultNewRowValue, "A1");
702 DataGridView dgv = new DataGridView ();
703 dgv.Columns.Add ("hi", "there");
705 DataGridViewRow row = new DataGridViewRow ();
709 Assert.AreEqual (null, dgv.Rows[0].Cells[0].DefaultNewRowValue, "A2");
713 public void Displayed ()
715 DataGridViewCell c = new BaseCell ();
716 Assert.AreEqual (false, c.Displayed, "A1");
718 DataGridView dgv = new DataGridView ();
719 dgv.Columns.Add ("hi", "there");
721 DataGridViewRow row = new DataGridViewRow ();
725 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Displayed, "A2");
729 public void EditedFormattedValue ()
731 DataGridViewCell c = new BaseCell ();
732 Assert.AreEqual (null, c.EditedFormattedValue, "A1");
736 public void FormattedValueType ()
738 DataGridViewCell c = new BaseCell ();
739 Assert.AreEqual (null, c.FormattedValueType, "A1");
743 public void Frozen ()
745 DataGridViewCell c = new BaseCell ();
746 Assert.AreEqual (false, c.Frozen, "A1");
748 DataGridView dgv = new DataGridView ();
749 dgv.Columns.Add ("hi", "there");
751 DataGridViewRow row = new DataGridViewRow ();
755 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Frozen, "A2");
757 dgv.Columns[0].Frozen = true;
758 dgv.Rows[0].Frozen = true;
759 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Frozen, "A3");
763 public void HasStyle ()
765 DataGridViewCell c = new BaseCell ();
766 Assert.AreEqual (false, c.HasStyle, "A1");
768 DataGridView dgv = new DataGridView ();
769 dgv.Columns.Add ("hi", "there");
771 DataGridViewRow row = new DataGridViewRow ();
775 Assert.AreEqual (false, dgv.Rows[0].Cells[0].HasStyle, "A2");
777 dgv.Rows[0].Cells[0].Style.BackColor = Color.Orange;
778 Assert.AreEqual (true, dgv.Rows[0].Cells[0].HasStyle, "A3");
782 public void InheritedState ()
784 DataGridViewCell c = new BaseCell ();
785 Assert.AreEqual (DataGridViewElementStates.ResizableSet, c.InheritedState, "A1");
787 DataGridView dgv = new DataGridView ();
788 dgv.Columns.Add ("hi", "there");
790 DataGridViewRow row = new DataGridViewRow ();
794 Assert.AreEqual (DataGridViewElementStates.ResizableSet | DataGridViewElementStates.Resizable | DataGridViewElementStates.Visible, dgv.Rows[0].Cells[0].InheritedState, "A2");
796 dgv.Rows[0].Selected = true;
797 Assert.AreEqual (DataGridViewElementStates.Selected | DataGridViewElementStates.ResizableSet | DataGridViewElementStates.Resizable | DataGridViewElementStates.Visible, dgv.Rows[0].Cells[0].InheritedState, "A3");
799 dgv.Rows[0].Selected = false;
800 dgv.Columns[0].Selected = true;
801 Assert.AreEqual (DataGridViewElementStates.ResizableSet | DataGridViewElementStates.Resizable | DataGridViewElementStates.Visible, dgv.Rows[0].Cells[0].InheritedState, "A4");
805 public void InheritedStyle ()
807 DataGridViewCell c = new BaseCell ();
808 DataGridView dgv = new DataGridView ();
809 dgv.Columns.Add ("hi", "there");
811 DataGridViewRow row = new DataGridViewRow ();
815 Assert.AreEqual (SystemColors.Window, dgv.Rows[0].Cells[0].InheritedStyle.BackColor, "A1");
817 dgv.DefaultCellStyle.BackColor = Color.Firebrick;
818 Assert.AreEqual (Color.Firebrick, dgv.Rows[0].Cells[0].InheritedStyle.BackColor, "A2");
820 dgv.Columns[0].DefaultCellStyle.BackColor = Color.FloralWhite;
821 Assert.AreEqual (Color.FloralWhite, dgv.Rows[0].Cells[0].InheritedStyle.BackColor, "A3");
823 dgv.RowsDefaultCellStyle.BackColor = Color.DeepPink;
824 Assert.AreEqual (Color.DeepPink, dgv.Rows[0].Cells[0].InheritedStyle.BackColor, "A4");
826 dgv.Rows[0].DefaultCellStyle.BackColor = Color.DeepSkyBlue;
827 Assert.AreEqual (Color.DeepSkyBlue, dgv.Rows[0].Cells[0].InheritedStyle.BackColor, "A5");
829 dgv.Rows[0].Cells[0].Style.BackColor = Color.DodgerBlue;
830 Assert.AreEqual (Color.DodgerBlue, dgv.Rows[0].Cells[0].InheritedStyle.BackColor, "A6");
834 public void IsInEditMode ()
836 DataGridViewCell c = new BaseCell ();
837 Assert.AreEqual (false, c.IsInEditMode, "A1");
839 DataGridView dgv = new DataGridView ();
840 dgv.Columns.Add ("hi", "there");
842 DataGridViewRow row = new DataGridViewRow ();
846 Assert.AreEqual (false, dgv.Rows[0].Cells[0].IsInEditMode, "A2");
850 public void OwningColumn ()
852 DataGridViewCell c = new BaseCell ();
853 Assert.AreEqual (null, c.OwningColumn, "A1");
855 DataGridView dgv = new DataGridView ();
856 dgv.Columns.Add ("hi", "there");
858 DataGridViewRow row = new DataGridViewRow ();
862 Assert.AreSame (dgv.Columns[0], dgv.Rows[0].Cells[0].OwningColumn, "A2");
866 public void OwningRow ()
868 DataGridViewCell c = new BaseCell ();
869 Assert.AreEqual (null, c.OwningRow, "A1");
871 DataGridView dgv = new DataGridView ();
872 dgv.Columns.Add ("hi", "there");
874 DataGridViewRow row = new DataGridViewRow ();
878 Assert.AreSame (dgv.Rows[0], dgv.Rows[0].Cells[0].OwningRow, "A2");
882 public void PreferredSize ()
884 DataGridViewCell c = new BaseCell ();
885 Assert.AreEqual (new Size (-1, -1), c.PreferredSize, "A1");
887 DataGridView dgv = new DataGridView ();
888 dgv.Columns.Add ("hi", "there");
890 DataGridViewRow row = new DataGridViewRow ();
894 Assert.AreEqual (new Size (-1, -1), dgv.Rows[0].Cells[0].PreferredSize, "A2");
896 // Always returns (-1, -1)
897 dgv.Rows[0].Cells[0].Value = "bob";
898 Assert.AreEqual (new Size (-1, -1), dgv.Rows[0].Cells[0].PreferredSize, "A3");
902 public void ReadOnly ()
904 DataGridViewCell c = new BaseCell ();
905 Assert.AreEqual (false, c.ReadOnly, "A1");
907 DataGridView dgv = new DataGridView ();
908 dgv.Columns.Add ("hi", "there");
910 DataGridViewRow row = new DataGridViewRow ();
914 Assert.AreEqual (false, dgv.Rows[0].Cells[0].ReadOnly, "A2");
916 dgv.Rows[0].ReadOnly = true;
917 Assert.AreEqual (true, dgv.Rows[0].Cells[0].ReadOnly, "A3");
919 dgv.Rows[0].Cells[0].ReadOnly = false;
920 Assert.AreEqual (false, dgv.Rows[0].Cells[0].ReadOnly, "A4");
924 public void Resizable ()
926 DataGridViewCell c = new BaseCell ();
927 Assert.AreEqual (false, c.Resizable, "A1");
929 DataGridView dgv = new DataGridView ();
930 dgv.Columns.Add ("hi", "there");
932 DataGridViewRow row = new DataGridViewRow ();
936 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Resizable, "A2");
938 dgv.Rows[0].Resizable = DataGridViewTriState.False;
939 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Resizable, "A3");
941 dgv.Columns[0].Resizable = DataGridViewTriState.False;
942 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Resizable, "A4");
944 dgv.Columns[0].Resizable = DataGridViewTriState.True;
945 dgv.Rows[0].Resizable = DataGridViewTriState.True;
946 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Resizable, "A5");
948 dgv.AllowUserToResizeColumns = false;
949 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Resizable, "A6");
951 dgv.AllowUserToResizeRows = false;
952 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Resizable, "A7");
954 dgv.Columns[0].Resizable = DataGridViewTriState.NotSet;
955 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Resizable, "A8");
957 dgv.Rows[0].Resizable = DataGridViewTriState.NotSet;
958 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Resizable, "A9");
962 public void RowIndex ()
964 DataGridViewCell c = new BaseCell ();
965 Assert.AreEqual (-1, c.RowIndex, "A1");
967 DataGridView dgv = new DataGridView ();
968 dgv.Columns.Add ("hi", "there");
970 DataGridViewRow row = new DataGridViewRow ();
974 Assert.AreEqual (0, dgv.Rows[0].Cells[0].RowIndex, "A2");
978 public void Selected ()
980 DataGridViewCell c = new BaseCell ();
981 Assert.AreEqual (false, c.Selected, "A1");
983 DataGridView dgv = new DataGridView ();
984 dgv.Columns.Add ("hi", "there");
986 DataGridViewRow row = new DataGridViewRow ();
990 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Selected, "A2");
992 dgv.Columns[0].Selected = true;
993 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Selected, "A3");
995 dgv.Rows[0].Selected = true;
996 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Selected, "A4");
998 dgv.Rows[0].Cells[0].Selected = false;
999 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Selected, "A5");
1001 dgv.Rows[0].Selected = false;
1002 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Selected, "A6");
1004 dgv.Rows[0].Cells[0].Selected = true;
1005 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Selected, "A7");
1008 /* The height of a cell (row) is based on Font
1012 DataGridViewCell c = new BaseCell ();
1013 Assert.AreEqual (new Size (-1, -1), c.Size, "A1");
1015 DataGridView dgv = new DataGridView ();
1016 dgv.Columns.Add ("hi", "there");
1018 DataGridViewRow row = new DataGridViewRow ();
1022 Assert.AreEqual (new Size (100, 22), dgv.Rows[0].Cells[0].Size, "A2");
1024 // Does not resize to content
1025 dgv.Rows[0].Cells[0].Value = "bob";
1026 Assert.AreEqual (new Size (100, 22), dgv.Rows[0].Cells[0].Size, "A3");
1031 public void Style ()
1033 DataGridViewCell c = new BaseCell ();
1034 Assert.AreEqual (DataGridViewContentAlignment.NotSet, c.Style.Alignment, "A1");
1035 Assert.AreEqual (Color.Empty, c.Style.BackColor, "A2");
1036 Assert.AreEqual (DBNull.Value, c.Style.DataSourceNullValue, "A3");
1037 Assert.AreEqual (null, c.Style.Font, "A4");
1038 Assert.AreEqual (Color.Empty, c.Style.ForeColor, "A5");
1039 Assert.AreEqual (string.Empty, c.Style.Format, "A6");
1040 Assert.AreEqual (Thread.CurrentThread.CurrentCulture, c.Style.FormatProvider, "A7");
1041 Assert.AreEqual (true, c.Style.IsDataSourceNullValueDefault, "A8");
1042 Assert.AreEqual (true, c.Style.IsFormatProviderDefault, "A9");
1043 Assert.AreEqual (true, c.Style.IsNullValueDefault, "A10");
1044 Assert.AreEqual (string.Empty, c.Style.NullValue, "A11");
1045 Assert.AreEqual (Padding.Empty, c.Style.Padding, "A12");
1046 Assert.AreEqual (Color.Empty, c.Style.SelectionBackColor, "A13");
1047 Assert.AreEqual (Color.Empty, c.Style.SelectionForeColor, "A14");
1048 Assert.AreEqual (null, c.Style.Tag, "A15");
1049 Assert.AreEqual (DataGridViewTriState.NotSet, c.Style.WrapMode, "A16");
1051 DataGridView dgv = new DataGridView ();
1052 dgv.Columns.Add ("hi", "there");
1054 DataGridViewRow row = new DataGridViewRow ();
1058 // Style does not change based on parent
1059 // (InheritedStyle does)
1060 Assert.AreEqual (DataGridViewContentAlignment.NotSet, c.Style.Alignment, "A17");
1061 Assert.AreEqual (Color.Empty, c.Style.BackColor, "A18");
1062 Assert.AreEqual (DBNull.Value, c.Style.DataSourceNullValue, "A19");
1063 Assert.AreEqual (null, c.Style.Font, "A20");
1064 Assert.AreEqual (Color.Empty, c.Style.ForeColor, "A21");
1065 Assert.AreEqual (string.Empty, c.Style.Format, "A22");
1066 Assert.AreEqual (Thread.CurrentThread.CurrentCulture, c.Style.FormatProvider, "A23");
1067 Assert.AreEqual (true, c.Style.IsDataSourceNullValueDefault, "A24");
1068 Assert.AreEqual (true, c.Style.IsFormatProviderDefault, "A25");
1069 Assert.AreEqual (true, c.Style.IsNullValueDefault, "A26");
1070 Assert.AreEqual (string.Empty, c.Style.NullValue, "A27");
1071 Assert.AreEqual (Padding.Empty, c.Style.Padding, "A28");
1072 Assert.AreEqual (Color.Empty, c.Style.SelectionBackColor, "A29");
1073 Assert.AreEqual (Color.Empty, c.Style.SelectionForeColor, "A30");
1074 Assert.AreEqual (null, c.Style.Tag, "A31");
1075 Assert.AreEqual (DataGridViewTriState.NotSet, c.Style.WrapMode, "A32");
1081 DataGridViewCell c = new BaseCell ();
1082 Assert.AreEqual (null, c.Tag, "A1");
1084 DataGridView dgv = new DataGridView ();
1085 dgv.Columns.Add ("hi", "there");
1087 DataGridViewRow row = new DataGridViewRow ();
1091 Assert.AreEqual (null, dgv.Rows[0].Cells[0].Tag, "A2");
1093 dgv.Rows[0].Cells[0].Tag = "bob";
1094 Assert.AreEqual ("bob", dgv.Rows[0].Cells[0].Tag, "A3");
1098 public void ToolTipText ()
1100 DataGridViewCell c = new BaseCell ();
1101 Assert.AreEqual (string.Empty, c.ToolTipText, "A1");
1103 DataGridView dgv = new DataGridView ();
1104 dgv.Columns.Add ("hi", "there");
1106 DataGridViewRow row = new DataGridViewRow ();
1110 Assert.AreEqual (string.Empty, dgv.Rows[0].Cells[0].ToolTipText, "A2");
1112 dgv.Rows[0].Cells[0].ToolTipText = "bob";
1113 Assert.AreEqual ("bob", dgv.Rows[0].Cells[0].ToolTipText, "A3");
1117 public void Value ()
1119 DataGridViewCell c = new BaseCell ();
1120 Assert.AreEqual (null, c.Value, "A1");
1122 DataGridView dgv = new DataGridView ();
1123 dgv.Columns.Add ("hi", "there");
1125 DataGridViewRow row = new DataGridViewRow ();
1129 Assert.AreEqual (null, dgv.Rows[0].Cells[0].Value, "A2");
1131 dgv.Rows[0].Cells[0].Value = "bob";
1132 Assert.AreEqual ("bob", dgv.Rows[0].Cells[0].Value, "A3");
1136 public void ValueType ()
1138 DataGridViewCell c = new BaseCell ();
1139 Assert.AreEqual (null, c.ValueType, "A1");
1141 DataGridView dgv = new DataGridView ();
1142 dgv.Columns.Add ("hi", "there");
1144 DataGridViewRow row = new DataGridViewRow ();
1148 Assert.AreEqual (null, dgv.Rows[0].Cells[0].ValueType, "A2");
1150 dgv.Rows[0].Cells[0].ValueType = typeof (bool);
1151 Assert.AreEqual (typeof (bool), dgv.Rows[0].Cells[0].ValueType, "A3");
1155 public void Visible ()
1157 DataGridViewCell c = new BaseCell ();
1158 Assert.AreEqual (false, c.Visible, "A1");
1160 DataGridView dgv = new DataGridView ();
1161 dgv.Columns.Add ("hi", "there");
1163 DataGridViewRow row = new DataGridViewRow ();
1167 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Visible, "A2");
1169 dgv.Columns[0].Visible = false;
1170 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Visible, "A3");
1172 dgv.Columns[0].Visible = true;
1173 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Visible, "A4");
1175 dgv.Rows[0].Visible = false;
1176 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Visible, "A5");
1178 dgv.Rows[0].Visible = true;
1179 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Visible, "A6");
1182 /* These can be used on windows to ensure the implementation
1183 * is correct, but are font-dependent
1185 public void MeasureTextHeight ()
1187 Bitmap b = new Bitmap (1, 1);
1188 Graphics g = Graphics.FromImage (b);
1191 int s = DataGridViewCell.MeasureTextHeight (g, "Text", Control.DefaultFont, 100, TextFormatFlags.Default, out trunc);
1193 //Assert.AreEqual (false, trunc, "A1");
1194 Assert.AreEqual (13, s, "A2");
1197 s = DataGridViewCell.MeasureTextHeight (g, "Text Longer than the width", Control.DefaultFont, 100, TextFormatFlags.Default, out trunc);
1199 //Assert.AreEqual (true, trunc, "A3");
1200 Assert.AreEqual (13, s, "A4");
1203 s = DataGridViewCell.MeasureTextHeight (g, "Text Longer than the width", Control.DefaultFont, 100, TextFormatFlags.HorizontalCenter, out trunc);
1205 //Assert.AreEqual (true, trunc, "A5");
1206 Assert.AreEqual (13, s, "A6");
1213 public void MeasureTextWidth ()
1215 Bitmap b = new Bitmap (1, 1);
1216 Graphics g = Graphics.FromImage (b);
1218 int s = DataGridViewCell.MeasureTextWidth (g, "Text", Control.DefaultFont, 100, TextFormatFlags.Default);
1220 Assert.AreEqual (28, s, "A1");
1222 s = DataGridViewCell.MeasureTextWidth (g, "Text Longer than the width", Control.DefaultFont, 100, TextFormatFlags.Default);
1224 Assert.AreEqual (134, s, "A2");
1226 s = DataGridViewCell.MeasureTextWidth (g, "Text Longer than the width", Control.DefaultFont, 100, TextFormatFlags.HorizontalCenter);
1228 Assert.AreEqual (134, s, "A3");
1235 public void MeasureTextSize ()
1237 Bitmap b = new Bitmap (1, 1);
1238 Graphics g = Graphics.FromImage (b);
1240 Size s = DataGridViewCell.MeasureTextSize (g, "Text", Control.DefaultFont, TextFormatFlags.Default);
1242 Assert.AreEqual (new Size (28, 13), s, "A1");
1244 s = DataGridViewCell.MeasureTextSize (g, "Text Longer than the width", Control.DefaultFont, TextFormatFlags.Default);
1246 Assert.AreEqual (new Size (134, 13), s, "A2");
1248 s = DataGridViewCell.MeasureTextSize (g, "Text Longer than the width", Control.DefaultFont, TextFormatFlags.HorizontalCenter);
1250 Assert.AreEqual (new Size (134, 13), s, "A3");
1252 s = DataGridViewCell.MeasureTextSize (g, "Text Longer \nthan the width", Control.DefaultFont, TextFormatFlags.HorizontalCenter);
1254 Assert.AreEqual (new Size (74, 26), s, "A4");
1261 public void MeasureTextPreferredSize ()
1263 Bitmap b = new Bitmap (1, 1);
1264 Graphics g = Graphics.FromImage (b);
1266 Size s = DataGridViewCell.MeasureTextPreferredSize (g, "Text", Control.DefaultFont, 1.5f, TextFormatFlags.Default);
1268 Assert.AreEqual (new Size (28, 13), s, "A1");
1270 s = DataGridViewCell.MeasureTextPreferredSize (g, "Text Longer than the width", Control.DefaultFont, 1.5f, TextFormatFlags.Default);
1272 Assert.AreEqual (new Size (134, 13), s, "A2");
1274 s = DataGridViewCell.MeasureTextPreferredSize (g, "Text Longer than the width", Control.DefaultFont, 2.0f, TextFormatFlags.Default);
1276 Assert.AreEqual (new Size (134, 13), s, "A3");
1278 s = DataGridViewCell.MeasureTextPreferredSize (g, "Text Longer \nthan the width", Control.DefaultFont, 0.5f, TextFormatFlags.Default);
1280 Assert.AreEqual (new Size (74, 26), s, "A4");
1288 public void MethodBorderWidths ()
1290 BaseCell c = new BaseCell ();
1292 DataGridViewAdvancedBorderStyle style = new DataGridViewAdvancedBorderStyle ();
1293 style.Bottom = DataGridViewAdvancedCellBorderStyle.Inset;
1294 style.Left = DataGridViewAdvancedCellBorderStyle.InsetDouble;
1295 style.Top = DataGridViewAdvancedCellBorderStyle.None;
1296 //style.Right = DataGridViewAdvancedCellBorderStyle.NotSet;
1298 Assert.AreEqual (new Rectangle (2, 0, 0, 1), c.PublicBorderWidths (style), "A1");
1300 style.Bottom = DataGridViewAdvancedCellBorderStyle.Outset;
1301 style.Left = DataGridViewAdvancedCellBorderStyle.OutsetDouble;
1302 style.Right = DataGridViewAdvancedCellBorderStyle.OutsetPartial;
1303 style.Top = DataGridViewAdvancedCellBorderStyle.Single;
1305 Assert.AreEqual (new Rectangle (2, 1, 1, 1), c.PublicBorderWidths (style), "A2");
1307 DataGridView dgv = new DataGridView ();
1308 dgv.Columns.Add ("hi", "there");
1310 DataGridViewRow row = new DataGridViewRow ();
1314 dgv.Rows[0].DividerHeight = 3;
1315 dgv.Columns[0].DividerWidth = 5;
1317 Assert.AreEqual (new Rectangle (2, 1, 6, 4), (dgv.Rows[0].Cells[0] as BaseCell).PublicBorderWidths (style), "A3");
1321 public void MethodGetContentBounds ()
1323 DataGridViewCell c = new BaseCell ();
1324 Assert.AreEqual (Rectangle.Empty, c.GetContentBounds (c.RowIndex), "A1");
1326 DataGridView dgv = new DataGridView ();
1327 dgv.Columns.Add ("hi", "there");
1329 DataGridViewRow row = new DataGridViewRow ();
1333 Assert.AreEqual (Rectangle.Empty, dgv.Rows[0].Cells[0].GetContentBounds (dgv.Rows[0].Cells[0].RowIndex), "A2");
1337 public void MethodGetContentBoundsOverload ()
1339 Bitmap b = new Bitmap (1, 1);
1340 Graphics g = Graphics.FromImage (b);
1342 BaseCell c = new BaseCell ();
1343 Assert.AreEqual (Rectangle.Empty, c.PublicGetContentBounds (g, c.Style, c.RowIndex), "A1");
1345 DataGridView dgv = new DataGridView ();
1346 dgv.Columns.Add ("hi", "there");
1348 DataGridViewRow row = new DataGridViewRow ();
1352 Assert.AreEqual (Rectangle.Empty, (dgv.Rows[0].Cells[0] as BaseCell).PublicGetContentBounds (g, dgv.Rows[0].Cells[0].InheritedStyle, dgv.Rows[0].Cells[0].RowIndex), "A2");
1358 public void MethodGetErrorIconBounds ()
1360 Bitmap b = new Bitmap (1, 1);
1361 Graphics g = Graphics.FromImage (b);
1363 BaseCell c = new BaseCell ();
1364 Assert.AreEqual (Rectangle.Empty, c.PublicGetErrorIconBounds (g, c.Style, c.RowIndex), "A1");
1366 DataGridView dgv = new DataGridView ();
1367 dgv.Columns.Add ("hi", "there");
1369 DataGridViewRow row = new DataGridViewRow ();
1373 Assert.AreEqual (Rectangle.Empty, (dgv.Rows[0].Cells[0] as BaseCell).PublicGetErrorIconBounds (g, dgv.Rows[0].Cells[0].InheritedStyle, dgv.Rows[0].Cells[0].RowIndex), "A2");
1379 public void MethodGetErrorText ()
1381 Bitmap b = new Bitmap (1, 1);
1382 Graphics g = Graphics.FromImage (b);
1384 BaseCell c = new BaseCell ();
1385 Assert.AreEqual (string.Empty, c.PublicGetErrorText (c.RowIndex), "A1");
1387 DataGridView dgv = new DataGridView ();
1388 dgv.Columns.Add ("hi", "there");
1390 DataGridViewRow row = new DataGridViewRow ();
1394 Assert.AreEqual (string.Empty, (dgv.Rows[0].Cells[0] as BaseCell).PublicGetErrorText (dgv.Rows[0].Cells[0].RowIndex), "A2");
1400 public void MethodKeyEntersEditMode ()
1402 bool result = false;
1403 DataGridViewCell c = new BaseCell ();
1405 foreach (Keys k in Enum.GetValues (typeof (Keys)))
1406 result |= c.KeyEntersEditMode (new KeyEventArgs (k));
1408 Assert.AreEqual (false, result, "A1");
1410 DataGridView dgv = new DataGridView ();
1411 dgv.Columns.Add ("hi", "there");
1413 DataGridViewRow row = new DataGridViewRow ();
1419 foreach (Keys k in Enum.GetValues (typeof (Keys)))
1420 result |= dgv.Rows[0].Cells[0].KeyEntersEditMode (new KeyEventArgs (k));
1422 Assert.AreEqual (false, result, "A2");
1426 public void MethodParseFormattedValue ()
1428 DataGridViewCell c = new FormattedBaseCell ();
1429 c.ValueType = typeof (bool);
1431 BooleanConverter bc = new BooleanConverter ();
1432 StringConverter sc = new StringConverter ();
1434 object o = c.ParseFormattedValue ("true", c.Style, sc, bc);
1435 Assert.AreEqual (true, (bool)o, "A1");
1439 public void MethodGetInheritedContextMenuStrip ()
1441 DataGridViewCell c = new BaseCell ();
1442 Assert.AreEqual (null, c.GetInheritedContextMenuStrip (c.RowIndex), "A1");
1444 DataGridView dgv = new DataGridView ();
1445 dgv.Columns.Add ("hi", "there");
1447 DataGridViewRow row = new DataGridViewRow ();
1451 Assert.AreEqual (null, dgv.Rows[0].Cells[0].GetInheritedContextMenuStrip (dgv.Rows[0].Cells[0].RowIndex), "A2");
1453 ContextMenuStrip cms1 = new ContextMenuStrip ();
1454 cms1.Items.Add ("Moose");
1455 dgv.ContextMenuStrip = cms1;
1457 Assert.AreSame (cms1, dgv.Rows[0].Cells[0].GetInheritedContextMenuStrip (dgv.Rows[0].Cells[0].RowIndex), "A3");
1459 ContextMenuStrip cms2 = new ContextMenuStrip ();
1460 cms2.Items.Add ("Moose");
1461 dgv.Columns[0].ContextMenuStrip = cms2;
1463 Assert.AreSame (cms2, dgv.Rows[0].Cells[0].GetInheritedContextMenuStrip (dgv.Rows[0].Cells[0].RowIndex), "A4");
1465 dgv.Rows[0].ContextMenuStrip = cms1;
1466 Assert.AreSame (cms1, dgv.Rows[0].Cells[0].GetInheritedContextMenuStrip (dgv.Rows[0].Cells[0].RowIndex), "A5");
1468 dgv.Rows[0].Cells[0].ContextMenuStrip = cms2;
1469 Assert.AreSame (cms2, dgv.Rows[0].Cells[0].GetInheritedContextMenuStrip (dgv.Rows[0].Cells[0].RowIndex), "A6");
1472 private class FormattedBaseCell : DataGridViewCell
1474 public override Type FormattedValueType { get { return typeof (string); } }
1477 private class BaseCell : DataGridViewCell
1479 public Rectangle PublicGetContentBounds (Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex)
1480 { return GetContentBounds (graphics, cellStyle, rowIndex); }
1481 public Rectangle PublicGetErrorIconBounds (Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex)
1482 { return GetErrorIconBounds (graphics, cellStyle, rowIndex); }
1483 public string PublicGetErrorText (int rowIndex)
1484 { return GetErrorText (rowIndex); }
1485 public Rectangle PublicBorderWidths (DataGridViewAdvancedBorderStyle advancedBorderStyle)
1486 { return BorderWidths (advancedBorderStyle); }
1489 class DataGridViewCellMockObject : DataGridViewCell
1491 public DataGridViewCellMockObject ()
1496 public class DataGridViewClipboardCell : DataGridViewCell
1498 public DataGridViewClipboardCell ()
1502 public object GetClipboardContentPublic (int rowIndex, bool firstCell, bool lastCell, bool inFirstRow, bool inLastRow, string format)
1504 return GetClipboardContent (rowIndex, firstCell, lastCell, inFirstRow, inLastRow, format);
1507 public override Type FormattedValueType
1511 return typeof (string);