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)来指定用于绑定的特定子列表。
新闻热点
疑难解答