Treeview控件 - 使用SQL数据源和闭包表方法 [英] Treeview Control - Using SQL datasource and closure table method

查看:58
本文介绍了Treeview控件 - 使用SQL数据源和闭包表方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,在Code Project这是我的第一篇文章!



对于所有有经验的vb开发人员,我的查询可能非常简单,但我来自Excel VBA开发人员背景,并尝试在很短的时间内学习使用Winforms,Visual Studio 2012和SQL Server进行开发,并正在寻找有关如何实现此目的的任何建议/指示,以避免任何已知的陷阱。



项目

我被要求从SQL表创建一个分层树视图,能够拖放节点并根据拖放的节点修改SQL表中的基础数据。



数据集是一个SQL表。 (> 30000条记录)主要相关字段是'TagNo',它是唯一的记录ID字段,'ParentTag'保存记录的父'TagNo'(如果有的话)。大约有5600个独特的ParentTag(即父级节点)



我的任务是使用'闭包表'方法(或祖先表方法,因为我')已经看到它提到了)因为我的老板喜欢这种实施方法。



采取的步骤



1:创建了一个包含SQL数据集的新Winforms应用程序(一个表显示了要在树视图中显示的所有设备),一个用于显示树视图的表单和一个用于此表单的树视图控件。



2:我已经阅读过:拖放方法,如何从SQL数据集构建树视图,设置上下文菜单等但是难以追踪任何将更改也写回数据集的示例。



我想知道/找到的内容



1:Closure Table方法是否适合此任务?如果是这样,一个从SQL表构建闭包表的简单方法?如果没有,你会建议采用什么方法?



2:任何已知的写入数据的示例都会在拖放节点后更改回基础数据集(即不仅仅是改变数据在树视图中的显示方式,但更新SQL数据表。)



任何有关方法,资源或示例的指针都会非常感激,因为我是有点被Treeview示例所淹没,其中没有一个似乎显示如何将更改写回基础SQL数据集?



我认为它是只是在触发拖放事件后运行UPDATE查询,但想要正确和有效地查看如何执行此操作,并且还希望看到闭包表方法的例子,如果有人实现了这个吗? />


提前谢谢。

Hi to all at Code Project this is my first post!

My query is probably very simple to all you experienced vb developers out there but I am from a Excel VBA developer background and trying to learn to develop using Winforms, Visual Studio 2012 and SQL Server in a very short time frame and am looking for any advice / pointers on how to achieve this avoiding any known pitfalls along the way.

The Project
I have been asked to create a hierarchical Treeview from a SQL table with the ability to drag and drop nodes and to also have the underlying data in the SQL table modifed as per the nodes dragged and dropped.

The dataset is one SQL table. (>30000 records) The main relevant fields are 'TagNo' which is a unique record ID field, and 'ParentTag' which hold the parent 'TagNo' (if any) for the record. There are roughly 5600 unique ParentTags (i.e. Parent level nodes)

I have been tasked to achieve this using the 'closure table' method (or Ancestor Tables method as I've seen it referred to) as my boss likes this method of implementation.

Steps Taken so Far

1: Created a new Winforms application containing a SQL dataset (one table showing all equipment to be displayed in treeview), a form to display the treeview and a treeview control on this form.

2: I have read up on: drag and drop methods, how to build a treeview from SQL dataset, setting context menus etc. but have had difficulty tracking down any examples where the changes are also written back to the dataset.

What I would like to know / find

1: Is the Closure Table method suitable for this task? If so, a simple method to build a closure table from the SQL table? If not, what method would you recommend instead?

2: Any known examples of writing data changes back to the underlying dataset after drag and drop of nodes (i.e. not just altering how the data is displayed in treeview but updating the SQL data table.)

Any pointers on methods, resources or examples of this would be greatly appreciated as I am a bit overwhelmed by the amount of 'Treeview' examples out there, none of which seem to show how to write the changes back to the underlying SQL dataset?

I presume it's just a matter of running UPDATE queries after the drag and drop event is triggered but would like to see how to do this "properly" and efficiently and would also like to see an exmaple of the closure table method if anyone has implemented this?

Thanks in advance.

推荐答案

好的,看起来我没有得到任何回复原始问题。可能太模糊了,因为我正在努力解决这个问题,而且我可能没有问正确的问题。



我现在真的只需要一个VB代码示例如何填充a使用我的Closure Table数据集进行树视图控制。



Closure Table包含一个'Level'字段,指示每个节点应显示在哪个级别。



我需要的是一个VB子实例,它循环遍历数据集中的所有行并填充到树视图。



有一点需要注意的是Closure Table保持约。 180,000行映射原始数据表中大约30,000个项目之间的所有可能连接。它基本上是一长串的系统/子系统/组件/子组件等等。这可以降到10多个级别。



关闭表结构



ID PartID ParentID Level



(其中'Level'是此节点的级别应该在Treeview层次结构中)



希望这有意义吗?当然有人在Visual Studio Winforms应用程序中必须做这样的事情吗?



任何建议或指示都将不胜感激。
OK, doesn't look like I'm getting any response to my original question. Probably way too vague as I'm struggling with this and am probably not asking the right questions.

I now realy only need an VB code example of how to populate a treeview control using my Closure Table dataset.

The Closure Table holds a 'Level' field, indicating at which level each node should be displayed at.

What I need is an example of a VB sub which loops through all the rows on the dataset and populates to the treeview.

One thing to note is that the Closure Table holds approx. 180,000 rows mapping all possible connections between roughly 30,000 items from the original data table. It is basically a long list of systems / sub systems / components / sub componants etc etc. This can go down to 10+ levels.

Closure Table Structure

ID PartID ParentID Level

(Where 'Level' is the level this node should be in the Treeview Hierarchy)

Hope this makes sense? Surely someone out there has had to do something like this in a Visual Studio Winforms application?

Any advice or pointers would be greatly appreciated.

这篇关于Treeview控件 - 使用SQL数据源和闭包表方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆