网格EX 行选择更改按钮单击不可见



我有一个gridEX组件和向上/向下按钮,用于相应地更改所选行。如果我从表中选择某行,向上按钮应选择先前选择的行上方的行。

private void btnUp_Click(object sender, EventArgs e)
{
//TODO
int rowIndex = gridEX.Row;
if (rowIndex > 0)
{
GridEXRow newSelectedRow = gridEX.GetRow(rowIndex-1);
gridEX.SelectedItems.Clear();
gridEX.MoveTo(newSelectedRow);   
}
}

上面的代码选择了正确的行,但选择是不可见的,就像我单击该行一样。 可能是什么问题?

单击向上/向下按钮会导致网格失去焦点。这就是所选行不突出显示的原因。在更改行之前,您需要将焦点设置回网格。像这样:

private void btnUp_Click(object sender, EventArgs e)
{
int rowIndex = gridEX1.CurrentRow.RowIndex - 1;
selectRow(rowIndex);
}
private void btnDown_Click(object sender, EventArgs e)
{
int rowIndex = gridEX1.CurrentRow.RowIndex + 1;
selectRow(rowIndex);
}
private void selectRow(int rowIndex)
{
gridEX1.Focus(); //set the focus back on your grid here
if (rowIndex >= 0 && rowIndex < (gridEX1.RowCount))
{               
GridEXRow newSelectedRow = gridEX1.GetRow(rowIndex);
gridEX1.MoveToRowIndex(rowIndex);               
}
}

最新更新