【问题标题】:VB.NET Custom Lookupeditor/comboboxVB.NET 自定义查找编辑器/组合框
【发布时间】:2015-07-29 09:03:05
【问题描述】:

在我的应用程序中,我有一些代码可以在几个表单中获取,我想知道是否有人可以就如何实现这一点提供一些建议。 我有 2 个应用程序可以使用的联系人列表(接口),并根据设置确定使用内部或外部联系人列表。我正在使用 devexpress 查找编辑器,但组合框的概念应该是相似的。

我正在做的是:

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

我想尝试实现的是创建一个自定义类/项目,我可以将其拖到我的表单上,并根据我的喜好重复使用它,而无需重新执行所有这些代码。希望我可以将一个查找编辑器拖到我的表单上,它会始终按照代码填充。

任何建议或方向都会很棒

【问题讨论】:

    标签: vb.net devexpress


    【解决方案1】:

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

        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
    

    然后当我需要设置查找编辑时,我只需调用:

     cbReportedToContactCode = classContactsFunctions.SetupContactsLookupEditor(cbReportedToContactCode)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-15
      • 2012-08-22
      • 2016-05-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多