diff --git a/X10D.WinForms/ListViewExtensions.cs b/X10D.WinForms/ListViewExtensions.cs new file mode 100644 index 0000000..e0dcd36 --- /dev/null +++ b/X10D.WinForms/ListViewExtensions.cs @@ -0,0 +1,35 @@ +namespace X10D.WinForms +{ + #region Using Directives + + using System.Windows.Forms; + + #endregion + + /// + /// A set of extension methods for and . + /// + public static class ListViewExtensions + { + /// + /// Moves the to the top of the specified . + /// + /// The to move. + /// Optional. The parent . Defaults to the current parent. + public static void MoveToTop(this ListViewItem item, ListView listView = null) + { + if (listView == null) + { + listView = item.ListView; + } + + if (listView.Items.Contains(item)) + { + int i = listView.Items.IndexOf(item); + listView.Items.RemoveAt(i); + } + + listView.Items.Insert(0, item); + } + } +} diff --git a/X10D.WinForms/X10D.WinForms.csproj b/X10D.WinForms/X10D.WinForms.csproj index 9fe7bc2..93359cd 100644 --- a/X10D.WinForms/X10D.WinForms.csproj +++ b/X10D.WinForms/X10D.WinForms.csproj @@ -43,6 +43,7 @@ +