How to recursively display tree effects in ComboBox

Source: Internet
Author: User
Http://community.csdn.net/Expert/topic/5229/5229675.xml? Temp =. 3458063. BM data table structure: ID name PID First, let's take a look at the types of trees:   1. display the simple tree structure with only spaces or other identical symbols, such:Liberal arts Chinese Composition reading English Spoken and Written sciences physical chemistry 2. Use different symbols to display the tree structure and use spaces to move the subnode to the right. For example:Liberal arts, Chinese, English, science, physics, mathematics 3. Use different symbols to display the tree structure and determine whether there are nodes of the same level and level at the next level. "Connection. Example:(1) liberal arts; (2) Chinese; (2); (2); (2); (2); (2); (2); (2); (2); (2); (2); (2); (2); (2); (2 ); 4. Use different symbols to display the tree structure and determine whether there are any next-level nodes. If yes, the front displays "+". If not Yes, "-" is displayed in the front, and then you can determine whether there are any nodes of the next level of the same level. If yes, use "Connections" to connect. For example:+ ┃ 文┣ ┣ + 文┃ ┣- ┗---English +-┗--math The following are four implementation methods:  First:The first method is the simplest. The first method is to implement the first method. The others are then supplemented. // first, the datatable public dataview DRV (string query) {oledbconnection conn = new oledbconnection () is created (); conn. connectionstring = "provider = Microsoft. jet. oledb.4.0; Data Source = D: \ xcrs. mdb "; Conn. open (); oledbdataadapter ADP = new oledbdataadapter (query, Conn); dataset DS = new dataset (); ADP. fill (DS, "BM"); Return Ds. tables ["BM"]. defaultview; Conn. close (); Conn. dispose ();} // The next step is to recursively load the data table // <summary> // recursive display-Treeview effect imitation // call the method: /// DV = DRV ("select * From BM"); // DV. sort = "pid asc"; // createtree (Treeview Control ID, dataview) /// </Summary> /// <Param name = "trvdbbinding"> name of the Treeview control to be bound </param> /// <returns> result </returns> Public void createcomboboxtree (ComboBox trvdbbinding, dataview DV) {datarowview [] arrdrv = DV. findrows (0); // get root data info int tnnew; If (arrdrv. length = 0) return; foreach (datarowview DR in arrdrv) {trvdbbinding. items. add (Dr ["name"]. tostring (); tnnew = convert. toint32 (Dr ["ID"]); createcomboboxtreenode (trvdbbinding, ref tnnew, DV ,"");}} /// <summary> /// recursive display-other controls Treeview effect imitation // tree Connection database ------ subnode /// </Summary> /// <Param name = "tnparent"> parent id </param> // <returns> result </returns> Public void createcomboboxtreenode (ComboBox trvdbbinding, ref int tnparent, dataview DV, string strfill) {datarowview [] arrdrv = DV. findrows (tnparent); // get children data info int tnnew; foreach (datarowview DR in arrdrv) {trvdbbinding. items. add (strfill + Dr ["name"]. tostring (); tnnew = convert. toint32 (Dr ["ID"]); createcomboboxtreenode (trvdbbinding, ref tnnew, DV, strfill + "");}} Call method:In the form_load event, write: dataview DV = DRV ("select * From BM"); DV. sort = "pid asc"; // Pai Xu createcomboboxtree (this. combobox1, DV );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.