[英]How to mark last row in DataGridView in case of vertical scroll bar?
[英]How to adjust vertical scroll position of DataGridView to show entire last row after changing its height?
我有一個DataGridView,通常每行顯示一行數據。 但是當用戶進入一個單元格時,我增加了最小高度以使編輯更加容易。 但是,在網格中的最后一行發生這種情況時,不會調整垂直滾動位置,並且只能看到該行的頂部,這通常會使它顯得空白。 將FirstDisplayedScrollingRowIndex設置為該行的索引並不能解決此問題。
這是我的代碼:
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();
}
我想我找到了答案。 它不一定像我希望的那樣優雅,因為它需要重寫另一種方法,從而將“修復”與“問題”分開。 但這似乎確實有效:
protected override void OnRowHeightChanged(DataGridViewRowEventArgs e)
{
base.OnRowHeightChanged(e);
if (CurrentRow == e.Row && e.Row.Index == RowCount - 1)
FirstDisplayedScrollingRowIndex = e.Row.Index;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.