0

我有一个 Winforms 应用程序,其中几个事件可以触发以下代码。. .

DataGridViewRow row = (DataGridViewRow)dataContactBusiness.CurrentCell.OwningRow;
int busID = (int)row.Cells["ID"].Value;
//...further processes utilising this ID

大多数情况下,这是可以的,但有可能在用户选择 DataGridView 上的一行之前或什至在填充 DataGridView 之前触发此代码。发生这种情况时,我得到一个异常“对象未设置为实例”等

什么是最好的测试方法

(a) DataGridView 有数据,并且 (b) 用户在该 DataGridView 中选择了一个单元格或行

4

1 回答 1

2

if (dataContactBusiness.CurrentCell != null) 成功了

于 2013-10-17T08:05:14.940 回答