views:

1031

answers:

2

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?

A: 

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.

jnosek
Your assumption is a bit wrong. I want to use the Forms AutoScroll and hide the DataGrids scroll bar. The DataGrid brings back about 700+ records so it takes up more than the whole visible area of the form. Perhaps I need to find out how many rows are in the datagrid and see how large that would be in pixels and set the datagrids height property to rows * pixels per row. Any ideas(I am not sure how to find out how many rows there are)
runxc1 Bret Ferrier
A: 

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
David House