I have a very simple form using the compact framework. I have two search fields a search button and a datagrid. The button sets the DataSource for a DataGrid on the form. I know that I can set the height and width on the DataGrid but I don't want the user to have to use the scroll bars on the DataGrid as it has a few hundred records. I just want the user to use the scroll bar on the form to scroll. How do I accomplish this?
I am assuming that the behavior you want is for a vertical scroll bar that spans the total height of the form to navigate through the records of the DataGrid
. This DataGrid
does not take up all the space on the form.
You could add a VScrollBar
to the side of the form and set its Maximum to the total row count of your DataGrid
. Then attach to the ValueChanged
event of the scroll bar and manipulate the selected row of your DataGrid
. This in effect would be mimicking the scrolling behavior of the DataGrid
.
The tricky part is hiding the scroll bar of the DataGrid
, as there is no property to hide it. You can extend its width so that the scroll bar is rendered off screen, but remember to set the Form's AutoScroll
property to false
so that it does not render a Horizontal scroll bar that would reveal the DataGrid
kludge.
Based on your application, you may want to look into using a ListView
with the View
property set to Details
. The ListView
is much easier to manipulate in the compact framework and might fit your application better. You can still use the same VScrollBar
technique above and apply it to the ListView
if you wish.
You must get the rowcount from the DataSource. Cast it like the enclosed example to produce the row count: (rsMissingItems is a SqlCEResultSet object)
Dim intRecCnt As Int32 = DirectCast(rsMissingItems.ResultSetView, ICollection).Count