예제 #1
0
        public void NonStringConverterTest()
        {
            CultureInfo originalCulture = CultureInfo.CurrentCulture;

            try
            {
                Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");

                table = new DataTable();
                view  = table.DefaultView;
                table.Columns.Add(new DataColumn("Amount", typeof(MockNumericNonStringConvertable)));

                DataRow row = table.NewRow();
                row ["Amount"] = new MockNumericNonStringConvertable(1);
                table.Rows.Add(row);

                row            = table.NewRow();
                row ["Amount"] = new MockNumericNonStringConvertable(2);
                table.Rows.Add(row);

                tableStyle = new DataGridTableStyle();
                ColumnPoker amountColumnStyle = new ColumnPoker();
                amountColumnStyle.MappingName = "Amount";
                tableStyle.GridColumnStyles.Add(amountColumnStyle);

                BindingContext bc = new BindingContext();
                DataGrid       dg = new DataGrid();
                dg.BindingContext = bc;
                dg.TableStyles.Add(tableStyle);
                dg.DataSource = table;

                CurrencyManager cm = (CurrencyManager)bc [view];
                TextBox         tb = amountColumnStyle.TextBox;

                Assert.IsNotNull(tb, "#A1");
                Assert.AreEqual(string.Empty, tb.Text, "#A2");

                amountColumnStyle.DoEdit(cm, 0, new Rectangle(new Point(0, 0), new Size(100, 100)), false, null, true);
                Assert.AreEqual("uno", tb.Text, "#B1");
                Assert.AreEqual(new MockNumericStringConvertable(1), table.Rows [0] ["Amount"], "#B2");

                amountColumnStyle.DoEdit(cm, 1, new Rectangle(new Point(0, 0), new Size(100, 100)), false, null, true);
                Assert.AreEqual("dos", tb.Text, "#C1");
                Assert.AreEqual(new MockNumericStringConvertable(2), table.Rows [1] ["Amount"], "#C2");

                amountColumnStyle.DoEdit(cm, 0, new Rectangle(new Point(0, 0), new Size(100, 100)), false, "£3.00", true);
                Assert.AreEqual("£3.00", tb.Text, "#D1");
                Assert.AreEqual(new MockNumericStringConvertable(1), table.Rows [0] ["Amount"], "#D2");

                Assert.IsTrue(amountColumnStyle.DoCommit(cm, cm.Position), "#E1");
                Assert.AreEqual("£3.00", tb.Text, "#E2");
                Assert.AreEqual("£3.00", table.Rows [0] ["Amount"], "#E3");
            }
            finally
            {
                Thread.CurrentThread.CurrentCulture = originalCulture;
            }
        }
예제 #2
0
		public void NonStringConverterTest ()
		{
			CultureInfo originalCulture = CultureInfo.CurrentCulture;

			try {
				Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-GB");

				table = new DataTable ();
				view = table.DefaultView;
				table.Columns.Add (new DataColumn ("Amount", typeof (MockNumericNonStringConvertable)));

				DataRow row = table.NewRow ();
				row ["Amount"] = new MockNumericNonStringConvertable (1);
				table.Rows.Add (row);

				row = table.NewRow ();
				row ["Amount"] = new MockNumericNonStringConvertable (2);
				table.Rows.Add (row);

				tableStyle = new DataGridTableStyle ();
				ColumnPoker amountColumnStyle = new ColumnPoker ();
				amountColumnStyle.MappingName = "Amount";
				tableStyle.GridColumnStyles.Add (amountColumnStyle);

				BindingContext bc = new BindingContext ();
				DataGrid dg = new DataGrid ();
				dg.BindingContext = bc;
				dg.TableStyles.Add (tableStyle);
				dg.DataSource = table;

				CurrencyManager cm = (CurrencyManager) bc [view];
				TextBox tb = amountColumnStyle.TextBox;

				Assert.IsNotNull (tb, "#A1");
				Assert.AreEqual (string.Empty, tb.Text, "#A2");

				amountColumnStyle.DoEdit (cm, 0, new Rectangle (new Point (0, 0), new Size (100, 100)), false, null, true);
				Assert.AreEqual ("uno", tb.Text, "#B1");
				Assert.AreEqual (new MockNumericStringConvertable (1), table.Rows [0] ["Amount"], "#B2");

				amountColumnStyle.DoEdit (cm, 1, new Rectangle (new Point (0, 0), new Size (100, 100)), false, null, true);
				Assert.AreEqual ("dos", tb.Text, "#C1");
				Assert.AreEqual (new MockNumericStringConvertable (2), table.Rows [1] ["Amount"], "#C2");

				amountColumnStyle.DoEdit (cm, 0, new Rectangle (new Point (0, 0), new Size (100, 100)), false, "£3.00", true);
				Assert.AreEqual ("£3.00", tb.Text, "#D1");
				Assert.AreEqual (new MockNumericStringConvertable (1), table.Rows [0] ["Amount"], "#D2");

				Assert.IsFalse (amountColumnStyle.DoCommit (cm, cm.Position), "#E1");
				Assert.AreEqual ("£3.00", tb.Text, "#E2");
				//Assert.AreEqual ("£3.00", table.Rows [0] ["Amount"], "#E3");
			} finally {
				Thread.CurrentThread.CurrentCulture = originalCulture;
			}
		}