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

Does dgvDAction.Rows.Count also equal 2?

Does dgvDAction.Rows.Count also equal 2?

how do i get the value or set it??

i have attached a doc on how it is showed when it runs.

thanxxxx

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.

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();
#
 
#
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.