Column named ABC cannot be found. Parameter name: columnName

  • Thread starter Thread starter Udan Fernando
  • Start date Start date
U

Udan Fernando

Guest
I have a grid-view with 3 column . the error fired inside the cell click event.

Column named Accname cannot be found.
Parameter name: columnName


Here is my code:



private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex == -1)
{

}
else
{
DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex];
try
{
tem_ID = row.Cells["AcId"].Value.ToString();
txt_gl_accountcode.Text = row.Cells["AcCode"].Value.ToString();

// I used to check the column name-> MessageBox.Show(dataGridView1.Columns[2].Name);

// Error is here-> txt_gl_aacountname.Text = row.Cells["Accname"].Value.ToString();


dataGridView1.Hide();

}
catch (Exception ex)
{
// MessageBox.Show("There is no data in this record Please enter new recored.","Maxxa Accounts",MessageBoxButtons.OK,MessageBoxIcon.Information);

MessageBox.Show(ex.Message.ToString() + "Passing From grid view mouseheder click");
}

}
}

Continue reading...
 
Back
Top