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.
我有一个gridView,我必须根据它旁边的单元格的值使单元格可编辑。就像第二列的单元格具有“AF”值一样,第一列的单元格将变为可编辑。我使用CellClick事件获得了解决方案。但问题是如果尝试键盘向下箭头或Enter按钮转到第一列的下一个单元格我无法使其可编辑。
This the code for cellClick event it is working fine.
这是cellClick事件的代码,它工作正常。
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;
}
}
}
}
2 个解决方案
#1
0
Perhaps use: e.KeyCode == Keys.Down
will solve it.
也许使用:e.KeyCode == Keys.Down将解决它。
#2
0
Instead of gridrowindex i used current row index and its working now.
而不是gridrowindex我使用当前行索引及其现在工作。
#1
0
Perhaps use: e.KeyCode == Keys.Down
will solve it.
也许使用:e.KeyCode == Keys.Down将解决它。
#2
0
Instead of gridrowindex i used current row index and its working now.
而不是gridrowindex我使用当前行索引及其现在工作。