unholymackerel
unholymackerel

Reputation: 89

VB.Net datagridview on tab page not returning row count unless user has viewed it

I have a tabcontrol. Each tabpage on the tabcontrol contains a datagridview. These are created programmatically.

Later I am reading values from the datagridviews and writing them to a Word document.

If the user has clicked on the tab page, the datagridview reports its correct row count.

If the user has not viewed the tab page, the datagridview .rowcount = 0

Is there something I can do to force the datagridview to reflect its actual rowcount?

I am navigating to the tab containing the datagridview by name (tcPlanFeeTab) with the following code:

           For Each tp As TabPage In frmSvcFee.tcPlanFee.TabPages
            'find the fee tab
            If tp.Text = tcPlanFeeTab Then 'this is the fee tab
                'select the tp so the datagridview is activated
                tp.Select()
                For Each ctl As Control In tp.Controls  'find the datagridview on the rates tab
                    If TypeOf ctl Is DataGridView Then
                        Dim D As DataGridView = ctl
                        MessageBox.Show(D.RowCount)

Upvotes: 1

Views: 1122

Answers (1)

David Hall
David Hall

Reputation: 33153

There is no way (that I know of) to force the grid to finish binding the data before the grid has been shown.

This is an optimization within the DataGridView itself.

Your best bet is to go to the underlying data source instead.

Upvotes: 2

Related Questions