2015-01-06 105 views
0

我有一个DataGridView,通常每行显示一行数据。但是当用户进入一个单元格时,我增加了最小高度以便编辑。但是,当网格中最后一行发生这种情况时,垂直滚动位置不会被调整,只有行的顶部可见,这通常会导致它显示为空白。将FirstDisplayedScrollingRowIndex设置为该行的索引不能解决此问题。如何调整DataGridView的垂直滚动位置以显示整个最后一行后改变其高度?

这里是我的代码:

protected override void OnCellEnter(DataGridViewCellEventArgs e) 
{ 
    base.OnCellEnter(e); 

    // Looks weird, but this solves an annoying problem where the wait cursor gets stuck 
    // on randomly after displaying one of the segmentation dialogs. 
    // See http://stackoverflow.com/questions/3008958/datagridview-retains-waitcursor-when-updated-from-thread/13808474#13808474 
    Cursor = Cursors.Default; 

    EditMode = (GetIgnoreStateForRow(CurrentCellAddress.Y)) ? DataGridViewEditMode.EditProgrammatically : DataGridViewEditMode.EditOnEnter; 
    if (e.ColumnIndex != 0 || CurrentCellAddress.Y < 0 || (!Focused && (EditingControl == null || !EditingControl.Focused))) 
    { 
     var minHeight = RowTemplate.Height * 3; 
     if (CurrentRow != null && CurrentRow.Height < minHeight) 
      CurrentRow.MinimumHeight = minHeight; 
     return; 
    } 
    SchedulePlaybackForCell(); 
} 

回答

0

我想我找到了答案。它不一定像我所希望的那样优雅,因为它要求压倒另一种方法,从而将“修复”与“问题”分开。但它似乎工作:

protected override void OnRowHeightChanged(DataGridViewRowEventArgs e) 
    { 
     base.OnRowHeightChanged(e); 
     if (CurrentRow == e.Row && e.Row.Index == RowCount - 1) 
      FirstDisplayedScrollingRowIndex = e.Row.Index; 
    } 
相关问题