or
public partial class AccountGroupList : AccountsFormBase { public AccountGroupList() { InitializeComponent(); accountGroupTreeView.NodeMouseDown += AccountGroupTreeViewNodeMouseDown; accountGroupTreeView.DragStarting += AccountGroupTreeViewDragStarting; accountGroupTreeView.DragOverNode += AccountGroupTreeViewDragOverNode; accountGroupTreeView.DragEnding += AccountGroupTreeViewDragEnding; accountGroupTreeView.ContextMenuStrip = contextMenuStrip; accountGroupTreeView.AllowDragDrop = true; accountGroupTreeView.MultiSelect = true; } protected override void OnDataBind() { FillAccountGroupTreeView(); } private void FillAccountGroupTreeView() { accountGroupTreeView.Nodes.Clear(); //find and add main account groups to tree foreach (AccountOrAccountGroupInfo mainAccountGroup in Model.AccountGroupHierarchy.Where(x => !x.EreportingId.HasValue && !x.ParentId.HasValue)) { var mainAccountGroupNode = new AccountGroupNode(mainAccountGroup.AccountGroup, true) {Tag = mainAccountGroup}; //find and add sub account groups of main account group foreach (AccountOrAccountGroupInfo subAccountGroup in Model.AccountGroupHierarchy.Where(x => !x.EreportingId.HasValue && x.ParentId == mainAccountGroup.Id)) { var subAccountNode = new AccountGroupNode(subAccountGroup.AccountGroup, false) { Tag = subAccountGroup }; //find and add ereporting accounts of sub account group foreach (AccountOrAccountGroupInfo eReportingAccount in Model.AccountGroupHierarchy.Where(x => x.EreportingId.HasValue && x.ParentId == subAccountGroup.Id)) { var eReportingAccountNode = new EreportingAccountNode(eReportingAccount.AccountGroup) {Tag = eReportingAccount, AllowDrop = false}; subAccountNode.Nodes.Add(eReportingAccountNode); } mainAccountGroupNode.Nodes.Add(subAccountNode); } //find and add ereporting accounts of main account group foreach (AccountOrAccountGroupInfo eReportingAccount in Model.AccountGroupHierarchy.Where(x => x.EreportingId.HasValue && x.ParentId == mainAccountGroup.Id)) { var eReportingAccountNode = new EreportingAccountNode(eReportingAccount.AccountGroup) { Tag = eReportingAccount }; mainAccountGroupNode.Nodes.Add(eReportingAccountNode); } accountGroupTreeView.Nodes.Add(mainAccountGroupNode); } //find and add ereporting accounts that are not linked to an account group foreach (AccountOrAccountGroupInfo eReportingAccount in Model.AccountGroupHierarchy.Where(x => x.EreportingId.HasValue && !x.ParentId.HasValue)) { var eReportingAccountNode = new EreportingAccountNode(eReportingAccount.AccountGroup) { Tag = eReportingAccount, AllowDrop = false }; accountGroupTreeView.Nodes.Add(eReportingAccountNode); } } #region drag, drop, context menu private void AccountGroupTreeViewDragStarting(object sender, RadTreeViewDragCancelEventArgs e) { try { //determine if dragging is allowed for selected node if (e.Node != null) { //An ereporting account node can be dragged var ereportingAccountNode = e.Node as EreportingAccountNode; if (ereportingAccountNode != null) { e.Cancel = false; } else { //A group node can only be dragged if it has no child groups var accountGroupNode = e.Node as AccountGroupNode; if (accountGroupNode != null) { e.Cancel = (accountGroupNode.SubAccountGroupCount > 0); } else { e.Cancel = true; } } } else { e.Cancel = true; } } catch (Exception) { e.Cancel = true; throw; } } private void AccountGroupTreeViewDragOverNode(object sender, RadTreeViewDragCancelEventArgs e) { try { //determine if the dragged node can be dropped on the current hovered node if (e.Node != null) { var accountNode = e.Node as AccountNodeBase; if (accountNode != null) { e.Cancel = !(accountNode.CanBeDroppedOnTarget(e.TargetNode)); } else { e.Cancel = true; } } else { e.Cancel = true; } } catch (Exception) { e.Cancel = true; throw; } } private void AccountGroupTreeViewDragEnding(object sender, RadTreeViewDragCancelEventArgs e) { try { //recheck if it is correct to drop the dragged node on the target node (this event is fired multiple times when multiple nodes are dragged at once) //execute the action that is expected var accountNode = e.Node as AccountNodeBase; if (accountNode != null) { if (accountNode.CanBeDroppedOnTarget(e.TargetNode)) { var draggedAccountGroupHierarchy = (AccountOrAccountGroupInfo)accountNode.Tag; var targetAccountGroupHierarchy = ((AccountOrAccountGroupInfo)e.TargetNode.Tag); if (e.Node is EreportingAccountNode) { Controller.MoveEreportingAccountToAccountGroup(draggedAccountGroupHierarchy.Id, targetAccountGroupHierarchy.Id); } else { Controller.MoveAccountGroupUnderAccountGroup(draggedAccountGroupHierarchy.Id, targetAccountGroupHierarchy.Id); } } else { e.Cancel = true; } } else { e.Cancel = true; } } catch (Exception) { e.Cancel = true; throw; } } #endregion #region Tree Node classes private abstract class AccountNodeBase : RadTreeNode { protected readonly Font TreeNodeFont = new Font("Segoe UI", 8.25f); public abstract bool CanBeDroppedOnTarget(RadTreeNode target); } private class AccountGroupNode : AccountNodeBase { public bool IsRootNode { get; private set; } public int SubAccountGroupCount { get { return Nodes.Count(o => o is AccountGroupNode); } } internal AccountGroupNode(string text, bool isRootNode) { Font = TreeNodeFont; Text = text; IsRootNode = isRootNode; } public override bool CanBeDroppedOnTarget(RadTreeNode target) { //a group node can be dropped on target if // -the target is also a group node // -the node has no child groups // -the node is a main group (level 1) // -the target node is not the current parent of the node var targetNode = target as AccountGroupNode; return targetNode != null && SubAccountGroupCount == 0 && targetNode.IsRootNode && targetNode != Parent; } } private class EreportingAccountNode : AccountNodeBase { internal EreportingAccountNode(string text) { Font = TreeNodeFont; Text = text; } public override bool CanBeDroppedOnTarget(RadTreeNode target) { //an ereporting node can be dropped on any group node that is not the current parent of the ereporting node if (!(target is EreportingAccountNode) && target != Parent) { return true; } return false; } } #endregion }Imagine the column Header is "Count" and the "Name" is "Column_0" In it's default behavior of the ListView it is sorted with this logic (as strings): 79 < 8 < 89 < 9 , .... The Designer's Code :privatevoidlistView1_ColumnClick(objectsender, System.Windows.Forms.ColumnClickEventArgs e){}I have written a comparer like this for the Default .Net Windows Forms Controls ListView :Telerik.WinControls.UI.ListViewDetailColumn listViewDetailColumn2 =newTelerik.WinControls.UI.ListViewDetailColumn("Column 1","Count");Telerik.WinControls.Data.SortDescriptor sortDescriptor1 =newTelerik.WinControls.Data.SortDescriptor();But now don't know how to link all the items and figure this out. needed help, thankspublicclassCountSort: IComparer{publicintCompare(objectx,objecty){Product w1 = (Product)x;Product w2 = (Product)y;if(w1.Count> w2.Count)return1;if(w1.Count< w2.Count)return-1;elsereturn0;}}
