/// <summary> /// Converts a <see cref="ListViewGroupEx"/> into a <see cref="LVGROUP2"/> (Native ListView Group) /// </summary> /// <param name="group">The <see cref="ListViewGroupEx"/> you want to convert</param> /// <returns></returns> public static LVGROUP2 ToNativeListViewGroup(this ListViewGroupEx group) { var nativeGroup = new LVGROUP2 { cbSize = (UInt32)Marshal.SizeOf(typeof(LVGROUP2)), mask = (UInt32)(GroupMask.LVGF_HEADER ^ GroupMask.LVGF_STATE ^ GroupMask.LVGF_GROUPID), stateMask = (UInt32)GroupState.LVGS_COLLAPSIBLE, state = (UInt32)GroupState.LVGS_COLLAPSIBLE, pszHeader = group.Header, iGroupId = group.Index }; if (group.Items.Any()) { nativeGroup.cItems = group.Items.Count(); nativeGroup.mask ^= (UInt32)GroupMask.LVGF_ITEMS; } return(nativeGroup); }