當我在datagridview中使用selectionchanged事件。 如果我單擊列標題,它會給我例外: NullReferenceException未被用戶代碼處理 對象引用未設置爲對象的實例。C#datagridview選擇更改事件錯誤
這是我的代碼
private void dgvEvents_SelectionChanged(object sender, EventArgs e)
{
//
//Select By EventID Operation.
//
eventID = int.Parse(dgvEvents.Rows[dgvEvents.CurrentRow.Index].Cells["EventID"].Value.ToString());
EventEntity = EventsMethods.SelectByID(eventID);
txtEventName.Text = EventEntity.Name;
cboxEventsCategories.SelectedValue = EventEntity.EventCategoryID;
dateTimePickerEvent.Text = EventEntity.Date.ToString();
txtBenefNum.Text = EventEntity.BeneficiariesNumber.ToString();
txtResultB.Text = EventEntity.ResultBefore.ToString();
txtResultA.Text = EventEntity.ResultAfter.ToString();
txtPercentage.Text = EventEntity.Percentage.ToString();
//
//Show EventsMembers.
//
FillEventsMembersDGV();
}
第6行的例外情況: –
eventID = int.Parse(dgvEvents.Rows [dgvEvents.CurrentRow.Index] .Cells [「EventID」]。Value.ToString()); –