i have a gridView and i have to make a cell editable based on the value of the cell beside of it. Like if the cell of second column is having "AF" value then the cell of the first column will become editable. I got the solution using CellClick event. But the problem is if try keyboard Down arrow or Enter button to go to next cell of the first column i am not able to make it editable.
This the code for cellClick event it is working fine.
private void dgvForecastData_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (GridRowIndex >= 0)
{
dgvForecastData.Rows[GridRowIndex].Cells["Forecast or Current Year Actual"].ReadOnly = true;
string sActForecastIndicator = dgvForecastData.Rows[GridRowIndex].Cells["Actual/Forecast Indicator"].Value.ToString().Trim();
if (sActForecastIndicator == "F" || sActForecastIndicator == "AF" && !dgvForecastData.Rows[GridRowIndex].Cells["Non recurring"].ReadOnly)
{
dgvForecastData.Rows[GridRowIndex].Cells["Forecast or Current Year Actual"].ReadOnly = false;
}
}
}
please tell me how can i achieve the above functionality using Keyboard(Down arrow and enter).
I am using the below code and it is not working
private void dgvForecastData_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Down)
{
if (GridRowIndex >= 0)
{
dgvForecastData.Rows[GridRowIndex].Cells["Forecast or Current Year Actual"].ReadOnly = true;
string sActForecastIndicator = dgvForecastData.Rows[GridRowIndex].Cells["Actual/Forecast Indicator"].Value.ToString().Trim();
if (sActForecastIndicator == "F" || sActForecastIndicator == "AF" && !dgvForecastData.Rows[GridRowIndex].Cells["Non recurring"].ReadOnly)
{
dgvForecastData.Rows[GridRowIndex].Cells["Forecast or Current Year Actual"].ReadOnly = false;
}
}
}
}
Instead of gridrowindex i used current row index and its working now.