HOW CHAGE VALUES IN CELLS DYNAMICALLY dATAGRIDVIEW
I HAVE A DATAGRIDVIEW BINDED TO A DATATABLE AND GRIDSETTINGS IS
//---------------------------------------------------------------------------------------------------------------------------------------------------
DataGridView1.Datasource = MyDatatable;
DataGridView1.EditMode = DataGridViewEditMode.EditOnEnter;
DataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.Sunken;
DataGridView1.Font = new Font("Times New Roman", 10);
DataGridView1.AllowUserToResizeRows = false;
DataGridView1.RowsDefaultCellStyle.BackColor = Color.GreenYellow;
DataGridView1.RowsDefaultCellStyle.ForeColor = Color.Blue;
DataGridView1.MultiSelect = false;
DataGridView1.RowHeadersVisible = false;
DataGridView1.Columns[4].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
DataGridView1.Columns[5].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
//-------------------------------------------------------------------------------------------------------------------------------------------------------
the last column is a check box column which is defined in datatable as
dtexam.Columns[7].DataType = System.Type.GetType("System.Boolean");
//------------------------------------------------------------------------------------------------------------------------------------------------------------
I WANT THAT WHEN USER CLICK ON CHECK BOX COLUMN IF IT IS CHECKED THE COLUMN 5 SHOULD BE SET TO ZERO IN THE SAME ROW . I M USING THIS CODE AT CELLCLICK
//--------------------------------------------------------------------------------------------------------------------------------------
try
{
int crow = DataGridView1.CurrentRow.Index;
string fl = DataGridView1.CurrentRow.Cells[7].Value.ToString();
Boolean bl = Boolean.Parse(fl);
if (bl == true)
{
//dgvexam.CurrentCell = dgvexam.SelectedCells[5];
DataGridView1.Rows[crow][5] = "0";
}
}
catch
{ }
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
but there is problem with this code that value desnot set to zero when cell is checked but sets to zero when I chaNge the row or I access the cell to which I want to assign value
please help me
hyder_master
|