当前位置: 首页>>代码示例>>C#>>正文


C# DataGridView.CreateControl方法代码示例

本文整理汇总了C#中System.Windows.Forms.DataGridView.CreateControl方法的典型用法代码示例。如果您正苦于以下问题:C# DataGridView.CreateControl方法的具体用法?C# DataGridView.CreateControl怎么用?C# DataGridView.CreateControl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Forms.DataGridView的用法示例。


在下文中一共展示了DataGridView.CreateControl方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DataSourceBindingContextDependency

		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");
		}
开发者ID:vnan122,项目名称:mono,代码行数:36,代码来源:DataGridViewTest.cs

示例2: CurrentCell

		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");
		}
开发者ID:vnan122,项目名称:mono,代码行数:57,代码来源:DataGridViewTest.cs


注:本文中的System.Windows.Forms.DataGridView.CreateControl方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。