0

I am using radgridview(winform) to display table values. I have a CellClick event for launching links for a particular column. The problem is that when I click to sort column at 3rd attempt it gives me error "Object Reference not set to instance of obj". While the users get error on every attempt after the first attempt. Here is my code -

private void radGridView1_CellClick(object sender, GridViewCellEventArgs e){
            index = radGridView1.CurrentCell.ColumnIndex;
            if(radGridView1.Columns[e.ColumnIndex].Name.Equals("ColumnName") 
               && index > 0)
            {
                Process.Start("http://www..../" + radGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value as string);
            }
}

I cannot figure out as why I am getting this error & how to resolve it. I tried to debug but every time I find index to be 0 and not null when I click the column header.

SOLUTION:

Instead of using ColumnIndex it should be e.rowindex

index = e.RowIndex;
if(radGridView1.Columns[e.ColumnIndex].Name.Equals("ColumnName") 
           && index != -1)
james andy
  • 59
  • 1
  • 10
  • If you want to get this question re-opened please make sure to provide real [MCVE]. So far there is unlikely any new hints to debug that are not already covered in "NRE & Fix" duplicate. – Alexei Levenkov Apr 06 '17 at 18:42
  • I know about the exception but my case if different. I am checking the int values and it's still coming to be 0 and not null. Does int have null values or if they don't is it still assigned as 0 even if it's null. And how to have a condition if excludes column header cell on cell click? – james andy Apr 06 '17 at 18:46
  • I have added solution to the question.. – james andy Apr 06 '17 at 19:42

0 Answers0