首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >VB.NET自定义Lookupeditor/组合框

VB.NET自定义Lookupeditor/组合框
EN

Stack Overflow用户
提问于 2015-07-28 13:15:31
回答 1查看 480关注 0票数 0

在我的应用程序中,我有一些代码可以放在几个表单上,我想知道是否有人可以提供一些关于如何实现这一点的建议。我有两个联系人列表(界面)可供应用程序使用,根据设置,它将确定使用内部联系人列表还是外部联系人列表。我使用的是devexpress lookupedit,但其概念应该与combobox类似。

我所做的是:

代码语言:javascript
复制
Dim dt As DataTable = classContactsFunctions.GetContactList()
        If dt.Rows.Count > 0 Then
            With cbSupervisorID
                .Properties.DataSource = dt  ' Specify the data source to display in the dropdown.
                .Properties.DisplayMember = "FullName"  ' The field providing the editor's display text.
                .Properties.ValueMember = "InterfaceCode" ' The field matching the edit value.
            End With
            ' Add two columns to the dropdown.
            Dim coll As DevExpress.XtraEditors.Controls.LookUpColumnInfoCollection = cbSupervisorID.Properties.Columns
            coll.Add(New DevExpress.XtraEditors.Controls.LookUpColumnInfo("InterfaceCode", 0))
            coll.Add(New DevExpress.XtraEditors.Controls.LookUpColumnInfo("Surname", 0))
            coll.Add(New DevExpress.XtraEditors.Controls.LookUpColumnInfo("FirstName", 0))
            cbSupervisorID.Properties.Columns("InterfaceCode").Visible = False
            With cbSupervisorID
                .Properties.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup    ' Set column widths according to their contents and resize the popup, if required
                .Properties.SearchMode = DevExpress.XtraEditors.Controls.SearchMode.AutoComplete            ' Enable auto completion search mode.
                .Properties.AutoSearchColumnIndex = 1                       ' Specify the column against which to perform the search.
            End With
        End If

我想要实现的是创建一个自定义的类/项,我可以将它拖到我的窗体上,并随时重复使用它,而不必重新执行所有这些代码。希望我只需将一个lookupedit拖到我的表单上,它将始终按照代码填充。

任何建议或方向都会很棒

EN

回答 1

Stack Overflow用户

发布于 2015-07-29 09:03:05

最终解决方案是将所有代码移到一个类中

代码语言:javascript
复制
    Shared Function SetupContactsLookupEditor(ByRef thelookup As LookUpEdit)
    Dim dt As DataTable = classContactsFunctions.GetContactList()
    If dt.Rows.Count > 0 Then

        With thelookup
            .Properties.DataSource = dt  ' Specify the data source to display in the dropdown.
            .Properties.DisplayMember = "FullName"  ' The field providing the editor's display text.
            .Properties.ValueMember = "InterfaceCode" ' The field matching the edit value.
        End With

        'Add two columns to the dropdown.
        Dim coll As LookUpColumnInfoCollection = thelookup.Properties.Columns
        coll.Add(New LookUpColumnInfo("InterfaceCode", 0))
        coll.Add(New LookUpColumnInfo("Surname", 0))
        coll.Add(New LookUpColumnInfo("FirstName", 0))
        ' thelookup.Properties.Columns("InterfaceCode").Visible = False

        With thelookup
            .Properties.BestFitMode = BestFitMode.BestFitResizePopup          ' Set column widths according to their contents and resize the popup, if required
            .Properties.SearchMode = SearchMode.AutoComplete        ' Enable auto completion search mode.
            .Properties.AutoSearchColumnIndex = 1         ' Specify the column against which to perform the search.
        End With

    End If
    Return thelookup
End Function

然后,当我需要设置lookupedit时,我只需调用:

代码语言:javascript
复制
 cbReportedToContactCode = classContactsFunctions.SetupContactsLookupEditor(cbReportedToContactCode)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31667831

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档