close

VB.net 自動滾動 DataGridView 的 ScrollBars

在對 DataGridView 作新增資料時,常會有 ScrollBars 不會自動滾動的困擾,


比如像這樣… Rows 一直增加… 但 ScrollBar 卻還是停留在最頂端…



之前採取的作法其實有點爛… 就是在新增完資料後,主動去選擇最後一個 Rows 的資料,使用這樣子的程式碼:


DataGridView1.CurrentCell = DataGridView1.Rows(DataGridView1.RowCount - 1).Cells(0)


但這種方式其實很難用… 而且畫面上也不好看:


而且基本上這種方式還必需把 DataGridView 的 AllowUserToAddRows 關掉才行,也就是如果使用者可以自行增加資料,那這個方式其實是無法作用的。

而且這應該也是偷懶的作法才對…

所以改採這個方式吧:


DataGridView1.FirstDisplayedScrollingRowIndex = DataGridView1.Rows.Count - 1


這樣子的自動滾動就會比較好看啦…而且也是個通用的方式…應該也是個正確的方式才對。

arrow
arrow
    全站熱搜

    JL8051 發表在 痞客邦 留言(0) 人氣()