【问题标题】:Combobox Datasource assign to Datatable组合框数据源分配给数据表
【发布时间】:2015-06-04 11:38:19
【问题描述】:

如何在 VB.net 中将 Combobox 的 Datasource 转换为 Datatable? 我知道如何assign datatable to combobox。在这种情况下,我需要以相反的方式进行。

喜欢:

dim dt as DataTable = combobox1.DataSource

这可能吗?

【问题讨论】:

    标签: vb.net combobox casting datatable


    【解决方案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
    

    【讨论】:

    • 谢谢。你拯救了我的一天
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-04
    • 1970-01-01
    • 1970-01-01
    • 2021-01-22
    • 2016-10-24
    相关资源
    最近更新 更多