Là một lập trình viên thương mại, tôi sử dụng một C# DLL để xử lý tất cả các dự án DataGridView tôi mang đến cho tôi sự tự do ngôn ngữ cho bất cứ dự án tôi thực hiện. Tất cả các chương trình của tôi đều bẫy tất cả các phím bấm để tôi có thể sử dụng chúng cho mục đích riêng của mình. Đối với DataGridView di chuyển, tôi sử dụng các phím PageUp/PageDown cho một trang duy nhất, Ctrl/Page cho một dòng và Alt/Page cho đầu (Lên) và dưới cùng (Xuống). C# mã và tự gọi điện thoại cơ bản như sau:
//---------- C# Dll Partial Source -----------
public int RowShow
{ get { return vu.DisplayedRowCount(false); } }
public int RowCount
{ get { return vu.RowCount; } }
public void PageMove(int rows)
{
int rowlimit = vu.RowCount - 1;
int calc = vu.FirstDisplayedScrollingRowIndex + rows;
if (calc > rowlimit) calc = rowlimit; // Go to bottom
if (calc < 0) calc = 0; // Go to top
vu.FirstDisplayedScrollingRowIndex = calc;
}
// ---------- End Data Grid View ----------
//---------- Calling Program C# ----------
public void Page_Key(int val, int lastKey)
{
int inc = 1; // vu is DataGridView
If (val == 33) inc = -1;
int rowsDisp = vu.RowShow; // # of rows displayed
int rowsMax = vu.RowCount; // # of rows in view
int rows = 0;
switch (lastKey)
{
case 17: // Ctrl prior to Page
rows = inc;
break;
case 19: // Alt prior to Page
rows = rowsMax * inc;
break;
default:
rows = rowsDisp * inc
break;
} // end switch
vu.PageMove(rows)
} // end Page_Key
'----- Calling Program B4PPC, VB -----
Sub Page_Key(val,lastKey) ' 33=PageUp, 34=Down
inc = 1 ' vu is DataGridView
If val = 33 then inc = -1
rowsDisp = vu.RowShow ' # of rows displayed
rowsMax = vu.RowCount ' # of rows in view
rows = 0
Select lastKey
Case 17 ' Ctrl prior to Page
rows = inc
Case 19 ' Alt prior to Page
rows = rowsMax * inc
Case Else
rows = rowsDisp * inc
End Select
lastKey = ""
vu.PageMove(rows)
End Sub
Nguồn
2013-01-25 17:10:15
thể trùng lặp của [DataGridView: Cuộn xuống tự động chỉ khi cuộn nằm ở phía dưới] (http://stackoverflow.com/questions/16263377/datagridview-scroll- down-automatic-only-if-the-scroll-is-at-the-bottom) –