组合框数据源分配给数据表

Combobox Datasource assign to Datatable

如何将组合框的数据源转换为VB.net中的数据表? 我知道如何assign datatable to combobox。在这种情况下,我需要以相反的方式进行。

喜欢:

dim dt as DataTable = combobox1.DataSource

这可能吗?

我会使用 TryCast 来完成工作。

Dim dt As DataTable = TryCast(combobox1.DataSource, DataTable)

If dt Is Nothing Then
    ' It didn't work because it's not a datatable
    ' Editors: I specifically did not reduce this expression
    '          to emphasize the need to check for 'Nothing'
    '          and handle it appropriately.
Else
    ' Yay it's a datatable
End If