翻譯|使用教程|編輯:龔雪|2025-07-10 10:45:30.300|閱讀 109 次
概述:本文主要介紹如何使用DevExpress WPF Grid控件檢查節點,歡迎下載最新版組件體驗!
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
DevExpress WPF擁有120+個控件和庫,將幫助您交付滿足甚至超出企業需求的高性能業務應用程序。通過DevExpress WPF能創建有著強大互動功能的XAML基礎應用程序,這些應用程序專注于當代客戶的需求和構建未來新一代支持觸摸的解決方案。 無論是Office辦公軟件的衍伸產品,還是以數據為中心的商業智能產品,都能通過DevExpress WPF控件來實現。
DevExpress技術交流群11:749942875 歡迎一起進群討論
用戶可以將復選框嵌入到節點中,并允許最終用戶選中/取消選中它們:
1. 將屬性設置為true來顯示嵌入到節點中的復選框。
2. 設置復選框的值,執行下列之一的操作:
下面的代碼示例展示了如何顯示復選框并將它們綁定到OnVacation字段:
Xaml
<dxg:GridControl Name="gridControl"> <dxg:GridControl.Columns> <dxg:GridColumn FieldName="Name"/> <dxg:GridColumn FieldName="Department"/> <dxg:GridColumn FieldName="Position"/> </dxg:GridControl.Columns> <dxg:GridControl.View> <dxg:TreeListView KeyFieldName="ID" ParentFieldName="ParentID" AutoExpandAllNodes="True" ShowCheckboxes="True" CheckBoxFieldName="OnVacation" /> </dxg:GridControl.View> </dxg:GridControl>
C#
public class Employee { public int ID { get; set; } public int ParentID { get; set; } public string Name { get; set; } public string Position { get; set; } public string Department { get; set; } public bool OnVacation { get; set; } }
VB.NET
Public Class Employee Public Property ID As Integer Public Property ParentID As Integer Public Property Name As String Public Property Position As String Public Property Department As String Public Property OnVacation As Boolean End Class
注意:在您聚焦另一行之前,TreeListView不會發布被聚焦行的復選框值。要使TreeListView post復選框立即有值,請將屬性設置為true。
使用以下成員在代碼中選中/取消選中節點:
當節點的檢查狀態改變時,TreeListView會引發事件,使用屬性來標識節點是否被檢查。
將屬性設置為true,允許最終用戶將節點的復選框設置為三種狀態當中的一個(選中,未選中或不確定):
TIP:在這種情況下,用戶可以指定一個復選框的狀態,而不管它的父和子的狀態。
TreeListNode.IsChecked屬性返回以下值:
設置屬性為true,如果您想讓控件根據子節點和父節點的選擇自動更新檢查狀態:
使用以下屬性將復選框的啟用狀態綁定到屬性:
注意:屬性優先于屬性。
下面的代碼示例展示了如何將復選框的啟用狀態綁定到Enabled字段:
Xaml
<dxg:GridControl Name="gridControl"> <dxg:GridControl.Columns> <dxg:GridColumn FieldName="Name"/> <dxg:GridColumn FieldName="Department"/> <dxg:GridColumn FieldName="Position"/> </dxg:GridControl.Columns> <dxg:GridControl.View> <dxg:TreeListView KeyFieldName="ID" ParentFieldName="ParentID" AutoExpandAllNodes="True" ShowCheckboxes="True" CheckBoxFieldName="OnVacation" IsCheckBoxEnabledFieldName="Enabled" /> </dxg:GridControl.View> </dxg:GridControl>
C#
public class Employee { public int ID { get; set; } public int ParentID { get; set; } public string Name { get; set; } public string Position { get; set; } public string Department { get; set; } public bool OnVacation { get; set; } public bool Enabled { get; set; } }
VB.NET
Public Class Employee Public Property ID As Integer Public Property ParentID As Integer Public Property Name As String Public Property Position As String Public Property Department As String Public Property OnVacation As Boolean Public Property Enabled As Boolean End Class
更多產品資訊及授權,歡迎來電咨詢:023-68661681
慧都是?家?業數字化解決?案公司,專注于軟件、?油與?業領域,以深?的業務理解和?業經驗,幫助企業實現智能化轉型與持續競爭優勢。
慧都是DevExpress的中國區的合作伙伴,DevExpress作為用戶界面領域的優秀產品,幫助企業高效構建權限管理、數據可視化(如網格/圖表/儀表盤)、跨平臺系統(WinForms/ASP.NET/.NET MAUI)及行業定制解決方案,加速開發并強化交互體驗。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都網