无法将当前单元格设置为 datagridview 中的不可见单元格 [英] Current cell cannot be set to an invisible cell in datagridview
问题描述
我在 datagridview 中遇到了问题.我在keydown事件中完成了一些代码,以便更改选项卡对焦但是当标签到达最后一个列时,它会出现错误
I am facing a problem in datagridview. I have done some code in keydown event for changing the tab focus but when tab reaches last of column it gives a error
当前单元格不能设置为不可见单元格".
"Current cell cannot be set to an invisible cell".
我已将最后一个单元格设为不可见,因为我不想让该单元格可见.
I have made last of cell is invisible because i don't want to be visible that cell.
我在 KeyDown 事件中编写了以下代码
I have written following code in KeyDown event
private void m3dgvDepositDetails_KeyDown(object sender, KeyEventArgs e)
{
try
{
if (e.KeyCode == Keys.Tab && notlastColumn)
{
e.SuppressKeyPress = true;
int iColumn = m3dgvDepositDetails.CurrentCell.ColumnIndex;
int iRow = m3dgvDepositDetails.CurrentCell.RowIndex;
if (iColumn == m3dgvDepositDetails.Columns.Count - 1)
m3dgvDepositDetails.CurrentCell = m3dgvDepositDetails[0, iRow + 1];
else
m3dgvDepositDetails.CurrentCell = m3dgvDepositDetails[iColumn + 1, iRow];
}
}
catch (Exception ex)
{
CusException cex = new CusException(ex);
cex.Show(MessageBoxIcon.Error);
}
}
推荐答案
该错误是不言自明的:您将 CurrentCell
设置为一个不可见的单元格并且被禁止,这意味着单元格的行或单元格的列被隐藏.为了避免这种情况,在设置 CurrentCell
之前不要隐藏行/列或检查 Visible
属性.
The error is quite self-explanatory: you are setting the CurrentCell
as an invisible cell and it is prohibited, that means that the cell's row or the cell's column is hidden. To avoid this don't hide rows/columns or check the Visible
property before setting the CurrentCell
.
如果问题是您应该使用的最后一列:
If the problem is the last column you should use:
private void m3dgvDepositDetails_KeyDown(object sender, KeyEventArgs e)
{
try
{
if (e.KeyCode == Keys.Tab && notlastColumn)
{
e.SuppressKeyPress = true;
int iColumn = m3dgvDepositDetails.CurrentCell.ColumnIndex;
int iRow = m3dgvDepositDetails.CurrentCell.RowIndex;
if (iColumn >= m3dgvDepositDetails.Columns.Count - 2)
m3dgvDepositDetails.CurrentCell = m3dgvDepositDetails[0, iRow + 1];
else
m3dgvDepositDetails.CurrentCell = m3dgvDepositDetails[iColumn + 1, iRow];
}
}
catch (Exception ex)
{
CusException cex = new CusException(ex);
cex.Show(MessageBoxIcon.Error);
}
}
这篇关于无法将当前单元格设置为 datagridview 中的不可见单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!