// DEBUGGING private void propPrinter(string fileLoc, ListView l) { string s = String.Empty; foreach (var prop in l.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public)) { if (prop.Name != "TopItem") { if (prop.GetValue(l, null) != null) s += (prop.Name + " = " + prop.GetValue(l, null).ToString() + Environment.NewLine); } } using (StreamWriter sWr = new StreamWriter(fileLoc)) { sWr.Write(s); } }
void EnableDoubleBuffering(ListView listView) { if (listView == null) return; var doubleBufferedProperty = listView.GetType().GetProperty( "DoubleBuffered", System.Reflection.BindingFlags.NonPublic | BindingFlags.Instance ); if (doubleBufferedProperty == null) return; doubleBufferedProperty.SetValue(listView, true, null); }
/// <summary> /// Patches the events for a specific ListView. /// </summary> /// <param name="lView">The source ListView.</param> private static void CorrectEventsForListView(ListView lView) { Delegate[] EventDelegates = null; if (EventsPatched.ContainsKey(lView)) throw new InvalidOperationException("Events for this list view has been previously patched: '" + lView.Name + "'"); EventsPatched.Add(lView, new Dictionary<string, List<Delegate>>()); foreach (string eventName in EventsToCorrect.Keys) { EventInfo eInfo = lView.GetType().GetEvent(eventName); if (eInfo == null) throw new InvalidOperationException("Event info for event '" + eventName + "' could not be found"); EventsPatched[lView].Add(eventName, new List<Delegate>()); EventDelegates = ContainerHelper.GetEventSubscribers(lView, eventName); if (EventDelegates != null) { foreach (Delegate del in EventDelegates) { EventsPatched[lView][eventName].Add(del); eInfo.RemoveEventHandler(lView, del); } } eInfo.AddEventHandler(lView, EventsToCorrect[eventName]); } }
/// <summary> /// In order to handle the property SmallIcons of a ListItem some Draw events must be handled. /// </summary> /// <param name="lView">The ListView source.</param> private static void PatchDrawItemEvents(ListView lView) { Delegate[] EventDelegates = null; bool PatchDrawItem = true; bool PatchDrawSubItem = true; bool PatchDrawColumnHeader = true; EventInfo eInfo = null; if (EventsPatched.ContainsKey(lView)) { //The events were previously patched if (EventsPatched[lView].ContainsKey(DrawItemEventName)) PatchDrawItem = false; if (EventsPatched[lView].ContainsKey(DrawColumnHeaderEventName)) PatchDrawColumnHeader = false; if (EventsPatched[lView].ContainsKey(DrawSubItemEventName)) PatchDrawSubItem = false; } else EventsPatched.Add(lView, new Dictionary<string, List<Delegate>>()); if (PatchDrawItem) { eInfo = lView.GetType().GetEvent(DrawItemEventName); if (eInfo == null) throw new InvalidOperationException("Event info for event '" + DrawItemEventName + "' could not be found"); EventsPatched[lView].Add(DrawItemEventName, new List<Delegate>()); EventDelegates = ContainerHelper.GetEventSubscribers(lView, DrawItemEventName); if (EventDelegates != null) { foreach (Delegate del in EventDelegates) { EventsPatched[lView][DrawItemEventName].Add(del); eInfo.RemoveEventHandler(lView, del); } } lView.DrawItem += new System.Windows.Forms.DrawListViewItemEventHandler(ListView_DrawItem); } if (PatchDrawColumnHeader) { eInfo = lView.GetType().GetEvent(DrawColumnHeaderEventName); if (eInfo == null) throw new InvalidOperationException("Event info for event '" + DrawColumnHeaderEventName + "' could not be found"); EventsPatched[lView].Add(DrawColumnHeaderEventName, new List<Delegate>()); EventDelegates = ContainerHelper.GetEventSubscribers(lView, DrawColumnHeaderEventName); if (EventDelegates != null) { foreach (Delegate del in EventDelegates) { EventsPatched[lView][DrawColumnHeaderEventName].Add(del); eInfo.RemoveEventHandler(lView, del); } } lView.DrawColumnHeader += new System.Windows.Forms.DrawListViewColumnHeaderEventHandler(ListView_DrawColumnHeader); } if (PatchDrawSubItem) { eInfo = lView.GetType().GetEvent(DrawSubItemEventName); if (eInfo == null) throw new InvalidOperationException("Event info for event '" + DrawSubItemEventName + "' could not be found"); EventsPatched[lView].Add(DrawSubItemEventName, new List<Delegate>()); EventDelegates = ContainerHelper.GetEventSubscribers(lView, DrawSubItemEventName); if (EventDelegates != null) { foreach (Delegate del in EventDelegates) { EventsPatched[lView][DrawSubItemEventName].Add(del); eInfo.RemoveEventHandler(lView, del); } } lView.DrawSubItem += new DrawListViewSubItemEventHandler(ListView_DrawSubItem); } lView.OwnerDraw = true; }
static string GetListViewState(ListView listview) { return listview.GetType().ToString() + ":" + ListViewUtil.GetColumnWidthListString(listview); }