Click here to Skip to main content
15,888,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
if (e.ColumnIndex >= 0)
{
DataRowView row = grid_emp_display.SelectedRows[0].DataBoundItem as DataRowView;
Gratuity_frm frm = new Gratuity_frm();
frm.row = row;
frm.ShowDialog();
}
Posted

1 solution

There are no selected rows. Therefore, when you try to access the first element of the array, it throws an exception.
This frequently occurs during SelectedValueChanged events when the application starts, becasue at that stage there are no selected items.
Always check first:
C#
if (e.ColumnIndex >= 0 && grid_emp_display.SelectedRows.Count > 0)
    {
    DataRowView row = grid_emp_display.SelectedRows[0].DataBoundItem as DataRowView;
    Gratuity_frm frm = new Gratuity_frm();
    frm.row = row;
    frm.ShowDialog();
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900