[DevExpress] Get the set of nodes in the visible region of TreeList, devexpresstreelist
Key code:
/// <Summary> /// obtain the nodes in the visible area /// </summary> /// <param name = "treeList"> TreeList </param> /// <param name = "conditonHanlder"> condition DeleGate </param> // <returns> visible region node set </returns> public static List <TreeListNode> GetVisibleNodes (this TreeList treeList, predicate <TreeListNode> conditonHanlder) {List <TreeListNode> _ visibleNodes = new List <TreeListNode> (); RowsInfo _ rowsInfo = treeList. viewInfo. rowsInfo; foreach (RowInfo ri in _ rowsInfo. rows) {TreeListNode _ curNode = ri. node; if (conditonHanlder (_ curNode) {_ visibleNodes. add (_ curNode) ;}} return _ visibleNodes ;} /// <summary> /// obtain the nodes in the visible area /// </summary> /// <param name = "treeList"> TreeList </param> /// <returns> visible region node set </returns> public static List <TreeListNode> GetVisibleNodes (this TreeList treeList) {return GetVisibleNodes (treeList, n => 1 = 1 );}
Code usage:
MessageBox.Show(tvwLamp.LHTree.GetVisibleNodes(n => n.GetNodeType() == NodeType.Cab).Count.ToString());
Hope this is helpful!
How to bind DevExpress in C # To XtraTreeList Parent and Child Nodes
This. treeList. DataSource = dt;
This. treeList. ParentFieldName = "Father_City_Id ";
This. treeList. KeyFieldName = "CityId ";
This is almost the case.
Q: How does the DEVExpress TreeList control bind data? Which event triggers binding? Now
Bind
Private void initTree ()
{
String sqltree = "select fitemid id, fnumber code, fname name, fparentid parentid from T_ITEM where fitemclassid = 4 and fdeleted = 0 and substring (fnumber, 1, 1) = '8' and fdetail = 0 ";
DataTable dtTree = SqlFunc. ExecSQL (sqltree );
TreeList1.DataSource = dtTree;
TreeList1.Columns ["id"]. Visible = false;
TreeList1.Columns ["parentid"]. Visible = false;
TreeList1.ExpandAll ();
GridView1.OptionsView. AllowCellMerge = true;
}
Click Event
Private void treelistpolicfocusednodechanged (object sender, DevExpress. XtraTreeList. FocusedNodeChangedEventArgs e)
{
DataRowView drv = (DataRowView) treeList1.GetDataRecordByNode (treeList1.FocusedNode );
DataRow dr = drv. Row;
Int p = Convert. ToInt32 (dr [0]);
..................
}