我想创建一个方法来选择当前行中的第一个单元格,所以我写了这个:
/// <summary>
/// The method selects first visible cell in a current row.
/// If current row is null, nothing is done.
/// If any cells are selected, they are unselected before selecting first cell.
/// </summary>
public void SelectFirstCellInCurrentRow()
{
if (CurrentRow == null) return;
ClearSelection();
foreach (DataGridViewCell cell in CurrentRow.Cells)
{
if (cell.Visible)
{
cell.Selected = true;
return;
}
}
}
我想这样使用它,例如:
private void btnAdd_Click(object sender, EventArgs e)
{
bindingSource.Add(new Customer());
bindingSource.MoveLast();
grid.SelectFirstCellInCurrentRow();
grid.BeginEdit(false);
}
它看起来是这样的:
2) 按下添加按钮后:
_http://img211.imageshack.us/img211/847/afteradd.gif
PS.为什么我不能添加图片?