This question has cropped up before and I thought that for convenience, I’d add a post as an anchor point.
In the Smart Office blog from our friendly Smart Office developers in Sweden, we have a post which answers the question that many of us had been asking for a long time. How to add a column to a ListView in Smart Office. As most of you know there are a number of traps and oddities around the ListView which make what you would expect to be a fairly simple task horribly complex.
(which is based off a great post by Thibaud here https://thibaudatwork.wordpress.com/2011/09/22/how-to-add-a-column-to-a-list/)
The one problem with this script is that it will break when you have an Editable cell in your ListView, and this is due to these two lines of code:
var newItems = new String[columnCount];
Specifically the creating the array as an array of strings rather than objects. The ListRow object that is bound to the ItemsSource has an array of objects – currently these can be either String objects OR Mango.UI.Services.Lists.EditableCell objects.
I used the Visual Studio debugger so I could see the objects below (I am preparing a more detailed article on how this works – it is pretty kewl what happens!)
See the Items property above – we have an array of object – one object for each column. The highlighted line above shows that the 4th item in the array is not a String. So instantly an exception will get thrown when we try to copy the EditableCell in to a String.
Correcting this is remarkably simple, we change line 43 in the linked article to read like this:
var newItems = new Object[columnCount];
The CopyTo will no longer throw an exception.