Click here to Skip to main content
15,906,330 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a gridview,I want to get SELECT column value and if it was true then get ID column value but i got the error :"index was out of range. must be non-negative and less than the size of
the collection "
my code:
C#
private void GrdSign_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            DataGridViewSelectedRowCollection rows = GrdSign.SelectedRows;
            if (Convert.ToBoolean(rows[0].Cells["Select"].Value))
            {
                signIDs += (string)rows[0].Cells["ID"].Value.ToString()+"#";
            }
        }
Posted
Comments
King Fisher 21-May-14 3:26am    
just copy the error and paste into google .you can find it Easily.

1 solution

Try

SQL
if(rows[0].Cells["Select"].value != string.Empty && rows[0].Cells["Select"].value != null)
{
if (Convert.ToBoolean(rows[0].Cells["Select"].Value))
            {
                signIDs += (string)rows[0].Cells["ID"].Value.ToString()+"#";
            }
}
 
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