Use the extended function method to quickly bind the tree list TreeList control and TreeListLookUpEdit control in the Winform interface
In some dictionary bindings, in order to facilitate the display of detailed data, some structural trees need to be displayed in the tree list TreeList control or the drop-down list tree control TreeListLookUpEdit control. In order to quickly process the data binding operation, compare each time For operations that involve too many details, we can put the relevant data binding operations in the extension functions of some auxiliary classes for processing. This can make the data binding operations more convenient and concise. This essay introduces TreeList. The processing operations of the control and the TreeListLookUpEdit control in the extension function.
In some dictionary bindings, in order to facilitate the display of detailed data, some structural trees need to be displayed in the tree list TreeList control or the drop-down list tree control TreeListLookUpEdit control. In order to quickly process the data binding operation, Compared with operations that involve too many details each time, we can put the relevant data binding operations in the extension functions of some auxiliary classes for processing, so that the data binding operations can be processed more conveniently and concisely. This article The essay introduces the processing operations of the TreeList control and the TreeListLookUpEdit control in the extension function.
1. Binding operation of TreeList control
TreeList itself is a tree data display control. It can display regular two-dimensional tables or two-dimensional tables with nested relationships. The data sources can be in a variety of ways and support the embedding of Datable data sources. Set of displays.
The tree list display interface effect of a single column information:
TreeList interface effect similar to GridView’s nested list display
These interfaces are relatively common, and they are also processing effects that we often encounter. However, the interface settings of TreeList have many features. If you copy these codes every time, it will require a lot and will not be easy to maintain, so we create some extension functions to handle them. The binding of interface elements is very necessary.
This essay introduces the binding based on the TreeList and TreeListLookUpEdit controls. The data sources of the two types of controls can be of the DataTable type or the IList collection type. As shown below, it is based on the SQLSugar development framework and the returned data structure is of the IList type.
So for general tree list binding operations, just provide a method to obtain data and bind it.
////// Binding tree data source /// private async void BindTree() { var list = await BLLFactory.Instance.GetAllAsync(); this.tree.DataSource = list?.Items; this.tree. ExpandAll(); }
If you use native code to initialize the tree list, the code is as follows.
//Use native code deal with //Add display Column this.tree.Columns.Add( new TreeListColumn{ FieldName= "Id", Caption= "ID"});//Add a hidden field to store the required ID static object BindDictItems(this TreeListLookUpEdit lookup, object dataSource, string displayMember, string valueMember, bool showRowIndicator = true, bool showCheckbox = false , string keyFieldName = null, string parentFieldName = null, string rootValue = null, bool editable = true, bool showColumnHeader = false , bool oddEvenRowColor = true, bool allowDrop = false, params LookUpColumnInfo[] lookUpColumnInfos) { lookup.Properties.DataSource = dataSource; lookup.Properties.DisplayMember = displayMember; lookup.Properties.ValueMember = valueMember; lookup.Properties.TreeList.OptionsView.ShowCheckBoxes = showCheckbox; lookup.Properties.TreeList.Columns.Clear(); for (int i = 0; i < lookUpColumnInfos.Length; i++) { lookup.Properties.TreeList.CreateColumn(lookUpColumnInfos[i].FieldName, lookUpColumnInfos[i].Caption, lookUpColumnInfos[i].Width, true); } //Initialize tree styles and features //keyFieldName = !string.IsNullOrWhiteSpace(keyFieldName) ? keyFieldName : valueMember;//If not specified, use valueMember lookup.Properties.TreeList.InitTree(keyFieldName, parentFieldName, rootValue, editable, showColumnHeader, oddEvenRowColor, allowDrop); lookup.Properties.PopupFormSize = new System.Drawing.Size(lookup.Width, 300); lookup.Properties.ImmediatePopup = true; lookup.Properties.TextEditStyle = TextEditStyles.Standard; if (showRowIndicator) { lookup.Properties.TreeList.IndicatorWidth = 40; //Rewrite Serial number display, the value is not displayed by default lookup.Properties.TreeList.CustomDrawNodeIndicator += (s, ee) => { if (ee. IsNodeIndicator) { var index = ee .Node.TreeList.GetVisibleIndexByNode(ee.Node); ee.Info.DisplayText = (index + 1).ToString(); } }; } return dataSource; }
By extending the method, the interface processing code can be simplified, and it will also help us quickly achieve related effects during project development without excessive interruptions in searching for related interface control properties.
There are several similar articles for reference:
“In Winform development, we use several drop-down lists to display dictionary data”
“Binding dictionary to drop-down list in Winform development framework and using cache to improve interface display speed”
“Use extension methods of common class libraries in various development projects to quickly call processing functions through context”
Focus on code generation tools, .Net/.NetCore framework architecture and software development, as well as various Vue.js front-end technology applications. He is the author of Winform development framework/hybrid development framework, WeChat development framework, Bootstrap development framework, ABP development framework, SqlSugar development framework and other framework products.
Please indicate the source for reprinting: Writer: Wu Huacong http://www.iqidi.com
an style=”color: rgba(128, 0, 128, 1)”>1).ToString();
}
};
}
return dataSource;
}
By extending the method, the interface processing code can be simplified, and it will also help us quickly achieve related effects during project development without excessive interruptions in searching for related interface control properties.
There are several similar articles for reference:
“In Winform development, we use several drop-down lists to display dictionary data”
“Binding dictionary to drop-down list in Winform development framework and using cache to improve interface display speed”
“Use extension methods of common class libraries in various development projects to quickly call processing functions through context”
Focus on code generation tools, .Net/.NetCore framework architecture and software development, as well as various Vue.js front-end technology applications. He is the author of Winform development framework/hybrid development framework, WeChat development framework, Bootstrap development framework, ABP development framework, SqlSugar development framework and other framework products.
Please indicate the source for reprinting: Writer: Wu Huacong http://www.iqidi.com