Use Treeview when displaying large-capacity database data

Source: Internet
Author: User
Because it takes a long time to use recursive algorithms when using Treeview to display large-capacity database data, users are required to wait for a long time. So how can we improve the user experience when using Treeview to display large-capacity database data?

This problem is well solved by the user's self-selection method.

The specific method is as follows:

Private void btnopendata_click (Object sender, eventargs E)
If (openfiledialog1.showdialog () = dialogresult. OK)
// Obtain the data source
Datafilename = openfiledialog1.filename;
String constring = @ "provider = Microsoft. Jet. oledb.4.0; Data Source =" + datafilename;

This. lbltishi. forecolor = color. Red;
This. lbltishi. Text = "the topic Resource Directory is being generated ...... ";
This. Refresh ();

DS. Clear ();
// Ds1.clear ();
Oledbconnection con = new oledbconnection ();

Con. connectionstring = constring;
Con. open ();
Oledbcommand cmd = new oledbcommand ();
Cmd. Connection = con;
Cmd. commandtext = "select * From tchannel order by channel_parentid ";
Cmd. commandtype = commandtype. text;
Oledbdataadapter da = new oledbdataadapter (CMD );
Da. Fill (DS );
Catch (exception ex)
Throw (Ex );
Con. Close ();

// Generate a level-1 tree directory
Treeview1.nodes. Clear ();
Treenode Tn = new treenode ("All column resources ");
This. treeview1.nodes. Add (TN );
Addtree ("0", TN );
Private void addtree (string parentid, treenode pnode)
// Use dataview to improve user experience, and add the next sub-directory "Please double-click to search for sub-resources (XXXXX)" under all sub-directories of the same level, so that you can expand it by double-clicking.
Dataview dvtree = new dataview (Ds. Tables [0]);
Dvtree. rowfilter = "channel_parentid = '" + parentid + "'";
Foreach (datarowview row in dvtree)
Treenode node = pnode. nodes. Add (row ["channel_name"]. tostring ());
Node. nodes. Add ("double-click to search for sub-resources (" + row ["channel_id"]. tostring () + ")");


Private void treeview1_nodemousedoubleclick_1 (Object sender, treenodemouseclickeventargs E)
// Obtain the Treeview from the double-clicked Node
Treeview TD = (Treeview) sender;
// Obtain the current node
Treenode Tn = TD. selectednode;
// Obtain the parent node of the current node
Treenode parenttn = tn. parent;
// Obtain the value of channel_id from "double-click to search for sub-resource (channel_id)" to find all the next nodes with the value of channel_parentid in the database;

Int start = tn. Text. lastindexof ("(");
Int end = tn. Text. lastindexof (")");
String channelparentid = tn. Text. substring (start + 1, end-start-1 );

// If the value is found, double-click the node "Please double-click to search for the sub-resource (channel_id.
// Delete the node to add a new subnode.
Tn. Remove ();
Addtree (channelparentid, parenttn );

// Otherwise, it is a valid node that has been searched. obtain the corresponding data resource path and query the data table.
Catch (argumentoutofrangeexception ee)
// Obtain the data resource path of the current node, and remove "All column resources \" on layer 0 to obtain the real data resource path.
This. lblcurdata. Text = tn. fullpath. substring (7 );
String channelid = This. lblcurdata. text;
Bindgrid (channelid, typestring, this. datetimepicker1.value, this. datetimepicker2.value); // query data operations
Catch (argumentoutofrangeexception ef)
This. lblcurdata. Text = "all columns ";
Bindgrid ("-", typestring, this. datetimepicker1.value, this. datetimepicker2.value );


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: 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.