錯誤名稱:
System.NullReferenceException: Object reference not set to an instance of an object. at 命名空間.類名.gridView1_FocusedRowChanged(Object sender, FocusedRowChangedEventArgs e) 代碼: //刪除操作 private void Btn_sc_Click(object sender, EventArgs e) { if (gridView1.FocusedRowHandle > -1) { string str = "delete from 表名 where 列名='" + CurrentRow[" 列名"].ToString() + "'"; 執行sql的函數 this.Browse(); MessageBox.Show("刪除成功"); } } //刷新界面 private void Browse() { string str = "select * from 表名"; ds=執行sql獲取ds的函數; gridControl1.DataSource = ds.Tables[0].DefaultView; } //獲取行變化 private void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e) { if (gridView1.FocusedRowHandle > -1) { if (CurrentRow["列名"].ToString() != null ) { //單步調試的時候,提出錯誤出在CurrentRow["列名"] } } }