【Visual Studio 擴展工具】如何在ComponentOneFlexGrid樹中顯示RadioButton

概述

在ComponentOne Enterprise .NET控件集中,FlexGrid表格控件是用戶使用頻率最高的控件之一。它是一個功能強大的數據管理工具,輕盈且靈動,以分層的形式展現數據(數據呈現更加直觀)。html

C1FlexGrid Hierarchy

FlexGrid 簡介

FlexGrid 是業界推崇的 .NET 數據表格,集成於 ComponentOne Enterprise .NET控件集中,可靈活、輕量、快速用於 WPF、WinForm、UWP、MVC、Silverlight、ActiveX平臺。node

分層數據展現

在分層數據展現中,FlexGrid 可使用Node.Checked屬性在任何節點行以前顯示CheckBox。 而後,父節點以前的這些複選框可用於添加功能,例如啓用/禁用或選擇/取消選擇樹中的全部子節點。安全

假設用戶想要利用RadioButton來代替這些複選框,而且,須要在對子節點進行「選擇/取消」按鈕操做時,同時影響父節點狀態的功能,利用 FlexGrid 數該如何實現?工具

C1FlexGrid RadioButtons

是否有可能在樹中顯示單選按鈕?

答案是確定的。 訣竅是使用 FlexGrid網格中子節點的Node.Image屬性顯示RadioButton圖像。性能

Node child = c1FlexGrid1.Rows.AddNode(1); child.Image = Image.FromFile("../../Resources/Img_Unchecked.png"); Node child = c1FlexGrid1.Rows.AddNode(1); child.Image = Image.FromFile("../../Resources/Img_Unchecked.png");

咱們剛剛展現了效果圖。 如今,咱們須要在改變「選中/取消」父節點時同時影響子節點狀態。 爲了知足這一要求,FlexGrid 網格的CellChecked事件將是一個不錯的選擇。當用戶改變父節點當前狀態時,它會被觸發。flex

private void C1FlexGrid1_CellChecked(object sender, RowColEventArgs e) { //Get the checked/unchecked node row Node node = c1FlexGrid1.Rows[e.Row].Node; //If node row is itself a parent if (node.Parent == null) { //If checked if (node.Checked == CheckEnum.Checked) { //For each child row foreach(Node childNode in node.Nodes) { //Enabled childNode.Row.AllowEditing = true; childNode.Row.StyleNew.BackColor = Color.White; } } //If unchecked else if(node.Checked == CheckEnum.Unchecked) { //For each child row foreach (Node childNode in node.Nodes) { //Disabled childNode.Row.AllowEditing = false; childNode.Row.StyleNew.BackColor = Color.LightGray; } } } } private void C1FlexGrid1_CellChecked(object sender, RowColEventArgs e) { //Get the checked/unchecked node row Node node = c1FlexGrid1.Rows[e.Row].Node; //If node row is itself a parent if (node.Parent == null) { //If checked if (node.Checked == CheckEnum.Checked) { //For each child row foreach(Node childNode in node.Nodes) { //Enabled childNode.Row.AllowEditing = true; childNode.Row.StyleNew.BackColor = Color.White; } } //If unchecked else if(node.Checked == CheckEnum.Unchecked) { //For each child row foreach (Node childNode in node.Nodes) { //Disabled childNode.Row.AllowEditing = false; childNode.Row.StyleNew.BackColor = Color.LightGray; } } } }

接下來,若是經過網格的MouseDown事件中的代碼啓用了子節點,它將處理單選按鈕的切換。spa

private void C1FlexGrid1_MouseDown(object sender, MouseEventArgs e) { HitTestInfo hti = c1FlexGrid1.HitTest(e.Location); //Get node row corresponding to clicked row Node node = c1FlexGrid1.Rows[hti.Row].Node; Rectangle cellBounds = c1FlexGrid1.GetCellRect(hti.Row, hti.Column); //If it is a child row if(node.Parent != null) { //Only for RadioButton if (hti.Column == 1 && node.Level == 1 && (hti.X >= cellBounds.X + 33) && (hti.X <= cellBounds.X + 43)) { //Check if enabled if(node.Row.AllowEditing) { //Currently unchecked if (Convert.ToInt32(node.Key) == 0) { //Checked state node.Image = Image.FromFile("../../Resources/Img_Checked.png"); node.Key = 1; } //Currently checked else { //Unchecked state node.Image = Image.FromFile("../../Resources/Img_Unchecked.png"); node.Key = 0; } } } } } private void C1FlexGrid1_MouseDown(object sender, MouseEventArgs e) { HitTestInfo hti = c1FlexGrid1.HitTest(e.Location); //Get node row corresponding to clicked row Node node = c1FlexGrid1.Rows[hti.Row].Node; Rectangle cellBounds = c1FlexGrid1.GetCellRect(hti.Row, hti.Column); //If it is a child row if(node.Parent != null) { //Only for RadioButton if (hti.Column == 1 && node.Level == 1 && (hti.X >= cellBounds.X + 33) && (hti.X <= cellBounds.X + 43)) { //Check if enabled if(node.Row.AllowEditing) { //Currently unchecked if (Convert.ToInt32(node.Key) == 0) { //Checked state node.Image = Image.FromFile("../../Resources/Img_Checked.png"); node.Key = 1; } //Currently checked else { //Unchecked state node.Image = Image.FromFile("../../Resources/Img_Unchecked.png"); node.Key = 0; } } } } }

在上面的代碼中,咱們在Node.Key屬性中存儲二進制狀態:0表示未檢查狀態,1表示已檢查狀態。code

C1FlexGrid in action

以上就是關於:如何在ComponentOne FlexGrid樹中顯示RadioButton的具體作法。與此同時,若是須要顯示RadioButton之外的控件,ComponentOne 也一樣支持!component


ComponentOne Enterprise | 下載試用

ComponentOne是一款專一於企業應用高性能開發的 .NET 全功能控件套包,包含300餘種控件,支持7大平臺,涵蓋7大功能模塊。較於市面上其餘同類產品,ComponentOne更加輕盈,功能更增強大,20多年的開發經驗,將爲您的應用系統帶來更爲安全的使用體驗。純中文操做界面,一對一技術支持,廠商級的技術服務,共同造就了這款國際頂級控件套包。orm

您對ComponentOne 產品的任何技術問題,都有技術支持工程師提供1對1專業解答,點擊此處便可發帖提問>> 技術支持論壇

相關文章
相關標籤/搜索