نمایش نتایج 1 تا 7 از 7

نام تاپیک: کار با TreeView و دیتابیس های رابطه ای.

  1. #1
    کاربر دائمی آواتار hdv212
    تاریخ عضویت
    آبان 1384
    محل زندگی
    قم
    پست
    1,727

    کار با TreeView و دیتابیس های رابطه ای.

    سلام
    میخواستم ببینم کسی از بچه ها با TreeView کار کرده ؟؟ اونم با دیتابیس های رابطه ای ؟؟ اگه کسی مقاله ای، آموزشی، چیزی داره به ما هم بده، مرسی.


  2. #2
    کاربر دائمی آواتار Sorenaa_s
    تاریخ عضویت
    اردیبهشت 1386
    سن
    40
    پست
    115
    دوست عزیز یک Design Pattern هست به اسم Composite که الگویی برای ساختارهای درختی طراحی شده. کد نمونه در این مورد رو میتونی تولینک زیر ببینی، با این روش به سادگی می تونی TreeView رو از DataBase پر کنی.

    http://www.dofactory.com/Patterns/PatternComposite.aspx

  3. #3
    کاربر دائمی آواتار ghafoori
    تاریخ عضویت
    مرداد 1384
    محل زندگی
    اصفهان-نجف اباد
    پست
    1,111

    Smile

    من داخل پروژه هام این کار را می کنم ابتدا از جدول اصلی یک یک رکورد ها را می خوانم برای انها یک node درست می کنم سپس جدول دوم که با جدول اول رابطه دارد براساس یک فیلد جدول دوم را براساس ان فیلتر مب کنم و برای رکورد های باقیمانده را node درست می کنم و فرزند نود اصلیم قرار می دهم

  4. #4
    کاربر دائمی آواتار hdv212
    تاریخ عضویت
    آبان 1384
    محل زندگی
    قم
    پست
    1,727
    متشکرم از راهنماییتون، من هم یه مفاله ای توی codeProject میخوندم که تقریبا مثل نظر ghafoori عزیز بود، منتها اون node های اصلی رو با جدول اصلی پر میکنه و در روبداد BeforExpanding مربوط به هر node، نودهای فرزند رو بهش اضافه میکنه، یعنی قبل از expand َدن هر node یه query انجام میشه، همینطور الی آخر، شاید این روش بهتری باشه، باز منتظر نظر دوستان میمونم ببینم چی میشه

  5. #5
    کاربر دائمی آواتار HAMRAHSOFT.IR
    تاریخ عضویت
    مرداد 1385
    محل زندگی
    هرجا كه غم و ناراحتي باشه
    پست
    1,174

    نقل قول: کار با TreeView و دیتابیس های رابطه ای.

    كسي نمونه كار با بانك اطلاعاتي اكسس در اين مورد كه بشه فقط يك فرزند يا پر انتخاب كرد و ايدي اون برگردون كنه نداره؟

  6. #6

    نقل قول: کار با TreeView و دیتابیس های رابطه ای.


    چجوری جداول و ویو های درون دیتا بیس را در تری ویو نمایش بدیم اگه میشه یه قطعه کد در این مورد بنویسید .

  7. #7
    کاربر دائمی آواتار k1csharpdeveloper
    تاریخ عضویت
    مهر 1389
    محل زندگی
    4باندی مهرشهر کرج
    سن
    37
    پست
    182

    نقل قول: کار با TreeView و دیتابیس های رابطه ای.

    Introduction


    This is a C#‎ implementation of data binding TreeView control. It can bind a regular TreeView control with multiple tables and display hierarchical data.
    Background


    When I was searching for such a data binding TreeView in C#‎, I could not find any, except a VB.NET version posted on MSDN. I decided to convert it to Visual C#‎. The original article and code, written by Duncan Mackenzie of MSDN, can be found at the link here. During the conversion, I found the original code to be too complicated. So, I made some changes to simplify the control itself and to make the use of the control easier.
    The Control


    Although I am not the original author of the control, I would like to introduce it to all C#‎ developers as I found it is a very useful and easy to use tree view control. The TreeView control can be bound to any data source supporting IList or IListSource. It uses the CurrencyManager object to access the bound data source. The CurrencyManager can also ensure that multiple controls bound to the same data source will stay on the same item in the data source. In the demo sample (mostly converted from the original sample), when you click a tree node, the right panel shows the related data bound to the same data source as the TreeView control.


    Using the code


    In the demo, data was retrieved from four Microsoft Access tables:



    After the data is retrieved into a DataView object, it can be bound to the TreeView control using its DisplayMember, ValueMember, and DataSource member properties as follows:
    Collapse | Copy Code
    this.myTree.DisplayMember = “title”; this.myTree.ValueMember = “title_id”; this.myTree.DataSource = this.myDataView;
    So far, data in the TreeView control is bound to the tables in a flat pattern. It displays only the book titles like this:



    In order to display data in hierarchy, the data needs to be sorted and grouped. From the data tables above, we can see that the data can be grouped by Publisher, Author, Title, or the combinations of them. To display the hierarchical data as shown in the beginning, the following code needs to be added for sorting and grouping:
    Collapse | Copy Code
    this.myDataView.Sort = “pub_id, au_id, title_id”; this.myTree.AddGroup ("Publisher", "pub_id", "pub_name", "pub_id", 0, 0); this.myTree.AddGroup ("Author", "au_id", "au_name", "au_id", 1, 3);
    It first groups the data by Publisher, and then by Author. Both the publisher and author nodes in the tree are group nodes, while the book title nodes are leaf nodes. Each of the nodes carry a Value member, which could be the IDs to identify themselves. In this case, the Value members are pub_id, au_id, and title_id.

    In the demo project, I added a menu to show how to change the groups. Groups can be added by checking the menu items, and removed by unchecking them. The following example groups data by Author and Title with publishers as leaves.



    Although you do not need to add a group for the leaves, you need to let the tree know which data group should be used as the leaves. For example, if the data is grouped by Publisher only, what will be the leaf nodes, the authors or the book titles? For this reason, I added a method in the TreeView control called SetLeafData(). You can set all the leaf data via the control’s member properties, such as DisplayMenmber, ValueMember, ImageIndex, etc. This method is just a simple way to do everything at once. It also assigns a name for the leaf group, which is useful when retrieving data from the nodes.

    This control contains useful functions to let you retrieve data from the nodes easily. Its FindNodeByValue() method allows you to locate a leaf node by its value. For example, if book titles are the leaf nodes and title_id is the value member of the nodes, entering a title ID will automatically select the book with that ID. The control’s FindNodeByPosition() method allows you to locate a leaf node by the row index in the data source.
    Changes made to the original code


    Besides what have been mentioned early, the major change was combining two derived TreeNode classes into one: dbTreeNode, and adding a method IsLeafNode(). The dbTreeNode class contains the following properties in addition to the regular TreeNode class:
    Collapse | Copy Code
    public String GroupName; // the name of the group public object Value; // the value member to identify the node public object Item; // the data row in the data source public int Position; // the row index in the data source
    The result of this change is the elimination of the following classes, methods, and events in the control and in the code using the control:
    Collapse | Copy Code
    // In the control: Classes: TreeGroupNode TreeLeavNode GroupTreeViewEventArgs GroupTreeViewCancelEventArgs LeafTreeViewEventArgs LeafTreeViewCancelEventArgs Methods: FindFirstLeafNode() OnBeforeSelect() OnAfterSelect() currcyManager_PositionChanged() Events: public delegate void BeforeGroupSelHandler() public event BeforeGroupSelHandler BeforeGroupSelect; public delegate void AfterGroupSelHandler() public event AfterGroupSelHandler AfterGroupSelect; public delegate void BeforeLeafSelHandler() public event BeforeLeafSelHandler BeforeLeafSelect; public delegate void AfterLeafSelHandler() public event AfterLeafSelHandler AfterLeafSelect; Event Handlers: private void currcyManager_PositionChanged() // In the code using the control: Event Handlers: private void myTree_BeforeGroupSelect() private void myTree_AfterGroupSelect() private void myTree_BeforeLeafSelect() private void myTree_AfterLeafSelect()
    The other change was adding the ability to disable the control’s auto-builder feature. In the original control, the tree was built or rebuilt whenever assigning a data source, adding a group, or removing a group. To display a three-level hierarchical tree as shown at the beginning, the tree was built 3 times. Only the last time, it generates the desired result. For large amounts of data, this would slow down the process, so I added an AutoBuilder property to allow this feature to be disabled. Once the auto-build feature is disabled, you need to call the BuildTree() function explicitly as follows:
    Collapse | Copy Code
    this.bookDataView.Sort = "pub_id, au_name, title_id"; this.myTree.DataSource = this.bookDataView; this.myTree.AddGroup ("Publisher", "pub_id","pub_name", "pub_id", 0,0); this.myTree.AddGroup ("Author", "au_id", "au_name", "au_id", 1, 3); this.myTree.SetLeafData ("Title", "title", "title_id", 2, 2); this.myTree.BuildTree();
    Conclusion


    I hope this is a useful tree-view control to you. Credits should be given to the original author Duncan Mackenzie of MSDN. As he said in the original article: “The data-bound Tree control shown in this article will not be the answer for every project that needs a Tree control to display information from a database, but it does illustrate one way in which you could customize this control for your own purposes. Keep in mind that the majority of the code in this control would be essentially the same in any complex data-bound control you wish to build, and that you can leverage that existing work to make future control development easier.”

    Once again, the original code and article can be found at the link here. When you read the original article, please note that some sections may not apply to this C#‎ implementation as many code have been eliminated. I wish that my modifications have simplified the original code without losing its functionalities, and that it will benefit C#‎ users.
    License


    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
    A list of licenses authors might use can be found here

    About the Author



    LZF

    Software Developer (Senior)

    United States

    Member

تاپیک های مشابه

  1. کار با Treeview !
    نوشته شده توسط rtech در بخش ASP.NET Web Forms
    پاسخ: 12
    آخرین پست: چهارشنبه 27 فروردین 1393, 01:17 صبح
  2. مشکل با TreeView
    نوشته شده توسط VisualStudio در بخش VB.NET
    پاسخ: 9
    آخرین پست: دوشنبه 02 شهریور 1388, 07:28 صبح
  3. انتخاب از TreeView
    نوشته شده توسط Ghalandari در بخش C#‎‎
    پاسخ: 2
    آخرین پست: سه شنبه 07 اسفند 1386, 17:08 عصر
  4. مشکل با TreeView
    نوشته شده توسط Alireza_Salehi در بخش ASP.NET Web Forms
    پاسخ: 4
    آخرین پست: دوشنبه 07 اسفند 1385, 20:43 عصر
  5. عدم نمایش Treeview
    نوشته شده توسط ar_monti@ در بخش ASP.NET Web Forms
    پاسخ: 2
    آخرین پست: پنج شنبه 12 بهمن 1385, 19:48 عصر

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •