Datagridview: valid datasource but empty datagridview RRS feed

  • Question

  • Hi,

    trying to figure out what's wrong but just can't.

    So I have a class that Inherit TabPage control to create my own custmize one. In that class I create my TabPage with all the needed controls for my program. This part works fine ... king of.

    When I start my program I use that class to create my first tab, and in that tab there's a Datagridview control. Then  the user can do a db search and it fill that datagridview. The user can, at that point, open one of the record into another instance of the customize TabPage, and that's where I have a problem I can't figure out.

    Here's the part of the code where I have the problem I don't understand:

    	Private Sub DoTheSearch(Optional MySQLstr As String = Nothing)
    			clsTabDataTable = New DataTable
    			If IsNothing(MySQLstr) Then
    				Dim frmCriteria = New SearchCriteriasForm
    				clsMainQueryStr = MainQueryStr
    				clsTabDataTable = clsGetSearchResults()
    				clsMainQueryStr = MainQueryStr
    				clsTabDataTable = clsGetSearchResults()
    			End If
    			If Not IsNothing(clsTabDataTable) Then
    				clsDgvMyResults.DataSource = clsTabDataTable
    				MsgBox("Aucun standard trouvé correspondant au(x) critère(s)", MsgBoxStyle.Exclamation, ProgramName)
    			End If
    		Catch ex As Exception
    			MsgBox(ex.Message & vbNewLine & vbNewLine & ex.StackTrace,, GetCurrentMethod().Name)
    		End Try
    	End Sub

    The "clsGetSearchResults()" is a function that return a DataTable.

    So on both time I create a tab I use that same sub, first shot no problem everything's fine. On the second, even though the datatable contain 71 rows and the datasource also, when I get to the line "MsgBox(clsDgvMyResults.Rows.Count)" the row count is zero, and the program really does not find any data in the datagridview.

    Any idea of why it's doing that?


    Thursday, October 31, 2019 2:52 PM

All replies

  • Hi,

    Can you upload a minimum size demo that will reproduce your question? Depending on your code, I can't tell where the problem is, whether it's a problem with your custom control or a problem with the code you posted.

    If you upload your code, please be careful to protect your privacy and delete your personal information.

    Best Regards,


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Friday, November 1, 2019 6:25 AM