DataGridView HorizontalScroll property throws NullReferenceException

0
1

I’m trying to synchronise horizontal scrolling for 2 DGVs (one acting as a footer) using the scroll event and setting HorizontalScroll.value but DGVs are throwing NullReferenceException when trying to reference Horizontal and Vertical Scroll properties (return Nothing).

Is this correct behavior for DataGridView.HorizontalScroll / DataGridView.VerticalScroll ?

thanks, Kingsley

  • You must to post comments
0
0

You can’t set the scroll position. You can scroll a cell or column or row into view.

The HorizontalScroll property doesn’t throw any exception. If it returns null and your code tries to use a null property then normally you get  a null reference exception.

  • You must to post comments
0
0

Hi Alaa

I’m trying to sync the scrolling between 2 grids like in https://wisej.com/support/question/datagridview-footer-1, but with the scrollbar at the bottom of both grids (could be the child scrollbar) controlling scroll position of both grids.

In the article Luca states…

“… You could add a second grid to the bottom without the column header and without the vertical scrollbar (see ScrollBars property) and then sync the column resize, move and horizontal scrolling on the client. You can also decide where to show the horizontal scrollbar… ”

I’ve had a look at the sample for that question in which the scroll synching works – parent grid scrolling moves child grid scroll. This I think is due to the child inheriting the parent container (DVG) scrolling (no code used).

I can’t find a way to set a grid’s scrollbar position. DVG has a HorizontalScroll.Value property this throws null exception (HorizontalScroll = null/nothing).

Sample from earlier question attached.

  • You must to post comments
0
0

Hi Kingsley,

Would you be able to wrap up a small sample that illustrates the issue?

Best,
Alaa

  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.