Multithreading with Forms and Controls

Choosing the DataTable is probably not something you want to have to do. You might be tempted to modify the code to set not only the DataSource property, but also the DataMember property, as shown here:

Sub DataReturnedEH(ByVal ReturnedDS As System.Data.DataSet)
   DataGrid1.DataSource = ReturnedDS
   DataGrid1.DataMember = ReturnedDS.Tables.Item(0).ToString
End Sub

Because there is only one table in the DataSet, you can use Tables.Item(0).ToString to retrieve the name of the first table in the DataTables collection.

Having made this change, if you happen to run the application, the results are less than desirable. In fact, you get an error, part of which says

 Controls created on one thread cannot be parented ...

Get A Programmer's Introduction to Visual Basic® .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.