Quasar/Quasar.Server/Controls/ListViewEx.cs

82 lines
2.9 KiB
C#
Raw Normal View History

using System;
using System.Windows.Forms;
using xServer.Core.Helper;
using xServer.Core.Utilities;
2014-07-08 12:58:53 +00:00
2015-01-13 18:29:11 +00:00
namespace xServer.Controls
2014-07-08 12:58:53 +00:00
{
internal class AeroListView : ListView
2014-07-08 12:58:53 +00:00
{
private const uint WM_CHANGEUISTATE = 0x127;
private const int UIS_SET = 1;
private const int UISF_HIDEFOCUS = 0x1;
2015-09-03 19:44:57 +00:00
private ListViewColumnSorter LvwColumnSorter { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="AeroListView"/> class.
/// </summary>
public AeroListView()
: base()
2014-07-08 12:58:53 +00:00
{
2015-05-30 06:47:19 +00:00
SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
2015-09-03 19:44:57 +00:00
this.LvwColumnSorter = new ListViewColumnSorter();
this.ListViewItemSorter = LvwColumnSorter;
this.View = View.Details;
this.FullRowSelect = true;
}
/// <summary>
/// Raises the <see cref="E:HandleCreated" /> event.
/// </summary>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
protected override void OnHandleCreated(EventArgs e)
{
base.OnHandleCreated(e);
2015-07-27 11:20:39 +00:00
if (PlatformHelper.RunningOnMono) return;
if (PlatformHelper.VistaOrHigher)
{
2015-07-27 11:20:39 +00:00
// set window theme to explorer
NativeMethods.SetWindowTheme(this.Handle, "explorer", null);
2015-07-27 11:20:39 +00:00
}
if (PlatformHelper.XpOrHigher)
{
// removes the ugly dotted line around focused item
NativeMethods.SendMessage(this.Handle, WM_CHANGEUISTATE,
NativeMethodsHelper.MakeLong(UIS_SET, UISF_HIDEFOCUS), 0);
}
2014-07-08 12:58:53 +00:00
}
2015-09-03 19:44:57 +00:00
/// <summary>
/// Raises the <see cref="E:ColumnClick" /> event.
/// </summary>
/// <param name="e">The <see cref="ColumnClickEventArgs"/> instance containing the event data.</param>
protected override void OnColumnClick(ColumnClickEventArgs e)
{
base.OnColumnClick(e);
// Determine if clicked column is already the column that is being sorted.
if (e.Column == this.LvwColumnSorter.SortColumn)
{
// Reverse the current sort direction for this column.
this.LvwColumnSorter.Order = (this.LvwColumnSorter.Order == SortOrder.Ascending)
? SortOrder.Descending
: SortOrder.Ascending;
}
else
{
// Set the column number that is to be sorted; default to ascending.
this.LvwColumnSorter.SortColumn = e.Column;
this.LvwColumnSorter.Order = SortOrder.Ascending;
}
// Perform the sort with these new sort options.
2018-09-13 13:34:03 +00:00
if (!this.VirtualMode)
this.Sort();
2015-09-03 19:44:57 +00:00
}
2014-07-08 12:58:53 +00:00
}
}