有時候我們對樹控制項的雙擊預設操作不太滿意,比如我們在雙擊一有子節點的節點的時候不希望開啟或關閉它的子節點而想執行乙個特定的操作,這時怎麼來寫呢,我這裡有乙個辦法可以做到這一點:
using system;using system.drawing;
using system.collections;
using system.***ponentmodel;
using system.windows.forms;
using system.data;
namespace treeviews
//////清理所有正在使用的資源。
///
protected
override void dispose( bool disposing )
}base.dispose( disposing );
}
#region windows 窗體設計器生成的**///
///
設計器支援所需的方法 - 不要使用**編輯器修改
///此方法的內容。
///
private
void initialize***ponent()
)}),
new system.windows.forms.treenode("節點3", new system.windows.forms.treenode )}),
new system.windows.forms.treenode("節點5", new system.windows.forms.treenode )})})}),
new system.windows.forms.treenode("節點2", new system.windows.forms.treenode ),
new system.windows.forms.treenode("節點3")});
this.treeview1.selectedimageindex = -1;
this.treeview1.size = new system.drawing.size(216, 232);
this.treeview1.tabindex = 0;
this.treeview1.click += new system.eventhandler(this.treeview1_click);
this.treeview1.beforecollapse += new system.windows.forms.treeviewcanceleventhandler(this.treeview1_beforecollapse);
this.treeview1.beforeexpand += new system.windows.forms.treeviewcanceleventhandler(this.treeview1_beforeexpand);
// // form1
//this.autoscalebasesize = new system.drawing.size(6, 14);
this.clientsize = new system.drawing.size(256, 266);
this.controls.add(this.treeview1);
this.name = "form1";
this.text = "form1";
this.resumelayout(false);
}#endregion
//////
應用程式的主入口點。
///
[stathread]
static
privatevoid treeview1_afterselect(object sender, system.windows.forms.treevieweventargs e)
}}
private bool tmpbool;//用來決定是否開啟或關閉樹的節點
privatevoid treeview1_click(object sender, system.eventargs e)
}}
privatevoid treeview1_beforeexpand(object sender, system.windows.forms.treeviewcanceleventargs e)
tmpbool = false;
}private
void treeview1_beforecollapse(object sender, system.windows.forms.treeviewcanceleventargs e)
tmpbool = false;}}
}
動態新增TREEVIEW的節點
讀取資料庫中的資料讓其插入到treeview的節點中,這裡是從資料庫中讀取省和直轄市新增到父節點中然後讀取省下的縣市新增到父節點下,建立了兩張個表乙個省的表,乙個是縣市表 using system using system.data using system.configuration using ...
動態新增treeview的節點
動態新增treeview的節點 主要控制項 treeview,imagelist,button 注意 treeview1.imagelist imagelist1 private subbutton1 click byvalsenderassystem.object,byvaleassystem.e...
遍歷TreeView得到選中的節點
region 遞迴treeview,把所有被選中的節點id記錄到arraylist中 遞迴treeview,把所有被選中的節點id記錄到arraylist中 private void recursivetree treeview tree 遞迴treeview的節點,把所有被選中的節點id記錄到ar...