

with dbtreecontrol .valuemember = "au_id" .displaymember = "au_lname" .datasource = mydatatable.defaultview .addgroup("publisher", "pub_id", "pub_name", "pub_id") .addgroup("title", "title_id", "title", "title_id") end with注意:這并不是我最終編寫的代碼行,但兩者相差不多。在開發控件的過程中,我意識到需要將與 treeview 關聯的 imagelist 中的圖像索引與每個分組級別相關聯,因此必須向 addgroup 方法中額外添加一個參數。

public class dbtreecontrol inherits system.windows.forms.treeview
private m_datasource as object<category("data")> _public property datasource() as object get return m_datasource end get set(byval value as object) if value is nothing then cm = nothing groupingchanged() else if not (typeof value is ilist or _ typeof value is ilistsource) then ' 不是針對該用途的有效數據源 throw new system.exception("無效 datasource") else if typeof value is ilistsource then dim mylistsource as ilistsource mylistsource = ctype(value, ilistsource) if mylistsource.containslistcollection = true then throw new system.exception("無效 datasource") else ' 對,對。它是有效的數據源 m_datasource = value cm = ctype(me.bindingcontext(value), _ currencymanager) groupingchanged() end if else m_datasource = value cm = ctype(me.bindingcontext(value), _ currencymanager) groupingchanged() end if end if end if end setend property注意:如果要支持此類對象(dataset 或與之類似的對象),您可以再添加一個屬性(如 datamember)來指定用于綁定的特定子列表。
新聞熱點
疑難解答