hi there, i get a Argument Out of Range Exception in the line "dgvDAction.Rows[r].Cells[0].Value = dt.Rows[r]["TActionDes"].ToString();" when it runs for the second time.dt.Rows.Count = 2.

why is this happening???

String query = @"Select TActionDes,TAssignTo,TDueDate,TStatus,TDateComplete,TComment from TopicAction Where TopicNo=@topicno and Phase=@phase ";
            SqlCommand command = new SqlCommand(query, DB.getConnection());
            
            command.Parameters.Add("@topicno", SqlDbType.VarChar).Value = tno;
            command.Parameters.Add("@phase", SqlDbType.Int).Value = phase;

            // DataGridViewCheckBoxColumn checkbox = (DataGridViewCheckBoxColumn)dgvDAction.Rows[0].Cells[3].OwningColumn;
            
            SqlDataAdapter da = new SqlDataAdapter(command);
            DataTable dt = new DataTable();
            
            da.Fill(dt);
            
            
            //dgvDAction.DataSource = dt;

           
            for (int r = 0; r < dt.Rows.Count ; r++)
            {
              //dgvDAction.Rows.Add();
                // dt.Rows[0]["TStatus"] = !((bool)dt.Rows[0]["TStatus"]);
                //dgvDAction.CurrentRow.Cells["Column3"].Value = "Vale is true";
                
                dgvDAction.Rows[r].Cells[0].Value = dt.Rows[r]["TActionDes"].ToString();
                dgvDAction.Rows[r].Cells[1].Value = dt.Rows[r]["TAssignTo"].ToString();
                dgvDAction.Rows[r].Cells[2].Value = dt.Rows[r]["TDueDate"].ToString();
                dgvDAction.Rows[r].Cells[3].Value = dt.Rows[r]["TStatus"].ToString();
                dgvDAction.Rows[r].Cells[4].Value = dt.Rows[r]["TDateComplete"].ToString();
               
                dgvDAction.Rows[r].Cells[5].Value = dt.Rows[r]["TComment"].ToString();

            }
            db10.closeConnection();

thanxxx

Set a breakpoint in the code and hover your mouse over what you want to see the value of.

Otherwise use the Immediate Window (bottom right of VS when app is running in debug mode)

Also in the bottom left you will see the values of every object that is currently in scope and being used by that scope.

Edited 6 Years Ago by Ketsuekiame: n/a

Set a breakpoint in the code and hover your mouse over what you want to see the value of.

Otherwise use the Immediate Window (bottom right of VS when app is running in debug mode)

Also in the bottom left you will see the values of every object that is currently in scope and being used by that scope.

do u know how to add rows to the datagrid in run mode to unbound data in the when the delow code runs

#
for (int r = 0; r < dt.Rows.Count ; r++)
#
{
#
//dgvDAction.Rows.Add();
#
// dt.Rows[0]["TStatus"] = !((bool)dt.Rows[0]["TStatus"]);
#
//dgvDAction.CurrentRow.Cells["Column3"].Value = "Vale is true";
#
 
#
dgvDAction.Rows[r].Cells[0].Value = dt.Rows[r]["TActionDes"].ToString();
#
dgvDAction.Rows[r].Cells[1].Value = dt.Rows[r]["TAssignTo"].ToString();
#
dgvDAction.Rows[r].Cells[2].Value = dt.Rows[r]["TDueDate"].ToString();
#
dgvDAction.Rows[r].Cells[3].Value = dt.Rows[r]["TStatus"].ToString();
#
dgvDAction.Rows[r].Cells[4].Value = dt.Rows[r]["TDateComplete"].ToString();
#
 
#
dgvDAction.Rows[r].Cells[5].Value = dt.Rows[r]["TComment"].ToString();
#
 
#
}
This article has been dead for over six months. Start a new discussion instead.