searchsanjaysharma
asked on
In C#, the datagridview is taking the control to top at every check on mouseup
I have a datagridview where in i have a checkbox along with some other fields, when i click on checkbox, the color of row becomes green if i check the checkbox else becomes green.
But everytime the cursor goes to top.
The code is attached.
private void dataGridView1_CellMouseUp_ 1(object sender, DataGridViewCellMouseEvent Args e)
{
try
{
if (e.ColumnIndex == 0)
{
DataGridViewRow dgvRow = dataGridView1.Rows[e.RowIn dex];
DataGridViewCheckBoxCell chkBox = (DataGridViewCheckBoxCell) (dgvRow.Ce lls[e.Colu mnIndex]);
SqlCommand cmd = new SqlCommand("updstssts", b.con);
cmd.CommandType = CommandType.StoredProcedur e;
cmd.Parameters.Add("@uid", SqlDbType.VarChar, 50).Value = dataGridView1.Rows[e.RowIn dex].Cells [1].Value. ToString() ;
if (Convert.ToBoolean(chkBox. Value))
{
cmd.Parameters.Add("@sts", SqlDbType.Char, 1).Value = 'U';
// dataGridView1.Rows[e.RowIn dex].Cells [0].Value = false ;
}
else
{
cmd.Parameters.Add("@sts", SqlDbType.Char, 1).Value = 'F';
// dataGridView1.Rows[e.RowIn dex].Cells [0].Value = true ;
}
if (b.con.State == ConnectionState.Closed)
{
b.con.Open();
}
cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
b.con.Close();
filgrd(e.RowIndex);
}
}
But everytime the cursor goes to top.
The code is attached.
private void dataGridView1_CellMouseUp_
{
try
{
if (e.ColumnIndex == 0)
{
DataGridViewRow dgvRow = dataGridView1.Rows[e.RowIn
DataGridViewCheckBoxCell chkBox = (DataGridViewCheckBoxCell)
SqlCommand cmd = new SqlCommand("updstssts", b.con);
cmd.CommandType = CommandType.StoredProcedur
cmd.Parameters.Add("@uid",
if (Convert.ToBoolean(chkBox.
{
cmd.Parameters.Add("@sts",
// dataGridView1.Rows[e.RowIn
}
else
{
cmd.Parameters.Add("@sts",
// dataGridView1.Rows[e.RowIn
}
if (b.con.State == ConnectionState.Closed)
{
b.con.Open();
}
cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
b.con.Close();
filgrd(e.RowIndex);
}
}
What "filgrd(e.RowIndex);" is doing in your code?
ASKER
The code is as follows
private void filgrd(int r)
{
try
{
string cor = b.pcbcor;
string sec = b.pcbsec;
b.con.Close();
SqlDataAdapter adp = new SqlDataAdapter("selstdbyco rsec", b.con);
adp.SelectCommand.Paramete rs.Add("@c or", SqlDbType.VarChar, 50).Value = cbcour.Text; ;
adp.SelectCommand.Paramete rs.Add("@s ec", SqlDbType.VarChar, 50).Value = cbsec.SelectedValue.ToStri ng();
adp.SelectCommand.CommandT ype = CommandType.StoredProcedur e;
DataSet ds = new DataSet();
adp.Fill(ds);
//ds.AcceptChanges();
// dataGridView1.DataSource = null;
dataGridView1.DataSource = ds.Tables[0];
bndgrd();
// dataGridView1.
}
catch (Exception ex) { MessageBox.Show("The Error is:" + ex.Message + ",Kindly take screen shot of this and send to sanjaysharmacgc@gmail.com" ); }
}
private void filgrd(int r)
{
try
{
string cor = b.pcbcor;
string sec = b.pcbsec;
b.con.Close();
SqlDataAdapter adp = new SqlDataAdapter("selstdbyco
adp.SelectCommand.Paramete
adp.SelectCommand.Paramete
adp.SelectCommand.CommandT
DataSet ds = new DataSet();
adp.Fill(ds);
//ds.AcceptChanges();
// dataGridView1.DataSource = null;
dataGridView1.DataSource = ds.Tables[0];
bndgrd();
// dataGridView1.
}
catch (Exception ex) { MessageBox.Show("The Error is:" + ex.Message + ",Kindly take screen shot of this and send to sanjaysharmacgc@gmail.com"
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
tx