在我的应用程序中,我有一些代码可以放在几个表单上,我想知道是否有人可以提供一些关于如何实现这一点的建议。我有两个联系人列表(界面)可供应用程序使用,根据设置,它将确定使用内部联系人列表还是外部联系人列表。我使用的是devexpress lookupedit,但其概念应该与combobox类似。
我所做的是:
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拖到我的表单上,它将始终按照代码填充。
任何建议或方向都会很棒
发布于 2015-07-29 09:03:05
最终解决方案是将所有代码移到一个类中
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时,我只需调用:
cbReportedToContactCode = classContactsFunctions.SetupContactsLookupEditor(cbReportedToContactCode)https://stackoverflow.com/questions/31667831
复制相似问题