1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern int SendMessage(
IntPtr hWnd, int msg, int wParam, int[] lParam);
private const int LVM_FIRST = 0x1000;
private const int LVM_GETCOLUMNORDERARRAY = (LVM_FIRST + 59);
/// <summary>
/// Gibt die aktuelle Reihenfolge der ListViewSpalten zurück.
/// </summary>
/// <param name="lv">ListView</param>
/// <returns>Indexe der sortierten Spalten.</returns>
public static int[] GetColumnOrder(this ListView lv)
{
int count = lv.Columns.Count;
int[] order = new int[count];
if (SendMessage(lv.Handle, LVM_GETCOLUMNORDERARRAY, count, order) == 0)
{
throw new ApplicationException(
"Spalten-Reihenfolge konnte nicht ermittelt werden.");
}
return order;
}
|