Furqan Sehgal
Furqan Sehgal

Reputation: 4997

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.

Upvotes: 1

Views: 5412

Answers (2)

ProblemAnswerQue
ProblemAnswerQue

Reputation: 545

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 ;)

Upvotes: 0

Miroslav Zadravec
Miroslav Zadravec

Reputation: 3740

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

Upvotes: 1

Related Questions