DataGridView scrolling
I have some data in my DataGridView. I want the user to be able to scroll through data but not select any 开发者_高级运维item. If I make enabled=false
, even scrolling does not work.
Secondly, the size of the gird is so that it show 10 items at the moment. I wish to show the selected item (selection done by code, not by user) whether it is item no. 15 or so.
Please advise how to manage it.
You can set the ReadOnly property for the grid and then set the style in such way that Foreground and Background colors of selected item are the same like those not selected. Items will actually be selected but selection wont be visible.
Private Sub SetMyStyle()
grid.ReadOnly = True
grid.DefaultCellStyle.SelectionForeColor = grid.DefaultCellStyle.ForeColor
grid.DefaultCellStyle.SelectionBackColor = grid.DefaultCellStyle.BackColor
grid.RowHeadersVisible = False
End Sub
About selection: to select 15th row and ensure it to be visible:
Private Sub SelectMyRow()
grid.ClearSelection()
grid.Rows(15).Selected = True
If Not grid.Rows(15).Displayed Then
grid.FirstDisplayedScrollingRowIndex = 15
End If
End Sub
for the size u should just go to the propertymenu for your datagrid, then go to Layout, AutoSizeColumnsMode and select Fill option there
and i would suggest to put the ReadOnly property on so that would do the trick :)
Have fun programmin ;)
精彩评论