如何在Comb.net中将Combobox的数据源转换为Datatable?
我知道如何assign datatable to combobox
。在这种情况下,我需要采取相反的方式。
像:
dim dt as DataTable = combobox1.DataSource
这可能吗?
答案 0 :(得分:1)
我会使用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