I have made a Windows forms application using c# and I am trying to add the edit and delete options in my datagridview. I have written the code for reordering of the columns using DisplayIndex as shown below but it throws a NullReferenceException and gives an error 'Object reference not set to an instance of an object'.I have included these statements in the FormName_Load method and I am using Visual Studio Professional 2013.
DataGridViewLinkColumn EditLink = new DataGridViewLinkColumn();
EditLink.UseColumnTextForLinkValue = true;
EditLink.HeaderText = "Edit";
//EditLink.DataPropertyName = dataGridView1.ToString();
EditLink.LinkBehavior = LinkBehavior.SystemDefault;
EditLink.Text = "edit";
dataGridView1.Columns.Add(EditLink);
dataGridView1.Columns["Edit"].DisplayIndex = 9;
//dataGridView1.Columns["Edit"].Visible = true;