Hello,
I'm using IronPython 2.6, Sharpdevelop 3.2 for GUI building and compiling, Pydev on Eclipse for writing the code and debugging.
I recently had some trouble using IronPython and ListView objects.
In my usecase I wanted to add ListViewItems i created in a thread very fast to an GUI ListView object.
First problem I ran into was the annoying flickering of the ListView when many Items have been added very fast.
To solve this issue I used this command on loading my GUI Form:
#self._listViewData was my used ListView object self._listViewData.GetType().GetProperty("DoubleBuffered", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).SetValue(self._listViewData, True, None)
` Well, this solved the flickering of the ListView while adding items.
My next problem was the ListView behaviour. When throwing hundreds or thousands of items into the ListView the ListView showed the scrolling items while adding them. And this took a loooong time, depending on the number of items.
To solve this issue, i used:
#self._listViewData was my used ListView object self._listViewData.BeginUpdate() #(function that adds my items) self._listViewData.EndUpdate()
As the process of adding items still was not as performant as I had expected, I was looking for a way to add the items more fluent and faster to the ListView.
Eventually I found a way to use the ListView method: AddRange(), from IronPython:
In my case, I used another ListView object to store my ListViewItems to add them later.
# I used an ListView object which I got from a thread, that builded every single ListViewItem and stored it in listViewBuffer listViewBuffer = getListViewItemsFromThread() # preparation listViewItemTemp = ListViewItem() listViewItemArray = [] # polling every ListViewItem from the listViewBuffer ListView-object # i know i could use: for listViewItemPiece in listViewBuffer.Items: # but this is closer to the code of my application for listViewItemNumber in range(listViewBuffer.Items.Count) listViewItemTemp = listViewBuffer.Items[listViewItemNumber] # some kind of filter for the ListViewItem. It allows me, to add just the wanted items to the GUI ListView. if itemFilter(listViewItemTemp): # I have to clone the items to use them in two ListView objects at the same time. listViewItemArray.append(listViewItemTemp.Clone()) # now adding the array of ListViewItems all at once to the GUI ListView self._listViewData.Items.AddRange(tuple (listViewItemsArray))
This three changes accellerated the way ListViewItems are added to the ListView - GUI a lot and improved the way the adding process is experienced by the user.
I would appreciate your comments and suggestions if there is a way to further improve or optimize this IronPython-Code to use the ListView - GUI.