I am using a DataGridView control in WinForm. When I click the ColumnHeader an Exception was met. it points to the line:
m_iSWId = Convert.ToInt32(DataGViewDetails.CurrentRow.Cells[8].Value.ToString()
i am getting NullReferenceException
How to solve this?
It seems
CurrentRowselects only rows not columns(column headers)Assuming you are doing this in
DataGridView_ClickEvent, Wrap your code with the below one: