예제 #1
0
		public void DataSourceBindingContextDependency ()
		{
			List<DataItem> dataList = new List<DataItem> ();
			dataList.Add (new DataItem ());
			dataList.Add (new DataItem ());

			DataGridView dgv = new DataGridView ();
			dgv.DataSource = dataList;
			Assert.IsNull (dgv.BindingContext, "#1");
			Assert.IsFalse (dgv.IsHandleCreated, "#2");
			Assert.AreEqual (0, dgv.RowCount, "#3");

			dgv.DataSource = null;

			Form form = new Form ();
			form.Controls.Add (dgv);
			dgv.DataSource = dataList;

			Assert.IsNotNull (dgv.BindingContext, "#4");
			Assert.IsFalse (dgv.IsHandleCreated, "#5");
			Assert.AreEqual (2, dgv.RowCount, "#6");

			dgv.Dispose ();
			dgv = new DataGridView ();
			dgv.DataSource = dataList;

			Assert.IsNull (dgv.BindingContext, "#7");
			Assert.IsFalse (dgv.IsHandleCreated, "#8");
			Assert.AreEqual (0, dgv.RowCount, "#9");

			dgv.CreateControl ();

			Assert.IsNull (dgv.BindingContext, "#10");
			Assert.IsTrue (dgv.IsHandleCreated, "#11");
			Assert.AreEqual (0, dgv.RowCount, "#12");
		}
예제 #2
0
		public void CurrentCell()
		{
			DataGridView dgv = new DataGridView ();
			dgv.AllowUserToAddRows = false;

			Assert.IsNull (dgv.CurrentCell, "A1");

			dgv.RowCount = 10;
			dgv.ColumnCount = 2;
			Assert.AreEqual (10, dgv.RowCount, "B1");
			Assert.AreEqual (2, dgv.ColumnCount, "B2");
			Assert.IsNull (dgv.CurrentCell, "B3");

			dgv.CurrentCell = dgv[1, 9];
			Assert.IsNotNull (dgv.CurrentCell, "H1");
			Assert.AreEqual (9, dgv.CurrentCell.RowIndex, "H2");
			Assert.AreEqual (1, dgv.CurrentCell.ColumnIndex, "H3");
			
			dgv.CurrentCell = null;
			Assert.IsNull (dgv.CurrentCell, "C1");

			dgv.CurrentCell = dgv[1, 9];
			Assert.IsNotNull (dgv.CurrentCell, "D1");
			Assert.AreEqual (9, dgv.CurrentCell.RowIndex, "D2");
			Assert.AreEqual (1, dgv.CurrentCell.ColumnIndex, "D3");

			dgv.RowCount = 9;
			Assert.IsNotNull (dgv.CurrentCell, "E1");
			Assert.AreEqual (8, dgv.CurrentCell.RowIndex, "E2");
			Assert.AreEqual (1, dgv.CurrentCell.ColumnIndex, "E3");

			dgv.CurrentCell = dgv[0, 4];
			dgv.RowCount = 2;
			Assert.IsNotNull (dgv.CurrentCell, "F1");
			Assert.AreEqual (1, dgv.CurrentCell.RowIndex, "F2");
			Assert.AreEqual (0, dgv.CurrentCell.ColumnIndex, "F3");

			dgv.RowCount = 0;
			Assert.IsNull (dgv.CurrentCell, "P1");

			dgv.RowCount = 10;
			Assert.AreEqual (10, dgv.RowCount, "I1");
			dgv.CurrentCell = dgv[0, 4];
			dgv.ColumnCount = 0;
			Assert.AreEqual (0, dgv.RowCount, "I2");
			Assert.IsNull (dgv.CurrentCell, "I3");

			dgv.RowCount = 0;
			dgv.ColumnCount = 0;
			dgv.CreateControl ();
			dgv.ColumnCount = 2;
			dgv.RowCount = 3;

			Assert.IsNotNull (dgv.CurrentCell, "G1");
			Assert.AreEqual (0, dgv.CurrentCell.RowIndex, "G1");
			Assert.AreEqual (0, dgv.CurrentCell.ColumnIndex, "G1");
		}