Question

Windows CE 5.0, NET Compact framework 3.5

I have faced with a very strange behavior of the ListView control. I extended the ListView control as below:

public partial class MyListView : ListView
{
  public void Fill(IEnumerable<string[]> data)
  {
    BeginUpdate();
    Items.Clear();
    foreach (var d in data) {
      Items.Add(new ListViewItem(d));
    }
    EndUpdate();
  }
}

And I have two similar devices with the same OS image. This code works fine with the first device, but it throws an exception at Items.Add with the second one. The exception does not appears each time, but very often. I cannot understand where is a problem. Do you have any ideas why that happen?

System.ArgumentOutOfRangeException was unhandled   Message="Exception" StackTrace:
       at Microsoft.AGL.Common.MISC.HandleAr(PAL_ERROR ar)
       at System.Windows.Forms.ListView.ntvGetColumnHeaderWidth(Int32 iColumn)
       at System.Windows.Forms.ColumnHeader.get_Width()
       at System.Windows.Forms.ListViewItem.ListViewSubItem.Actualize(Int32 index)
       at System.Windows.Forms.ListViewItem.ListViewSubItemCollection.Actualize()
       at System.Windows.Forms.ListView.ListViewItemCollection.Insert(Int32 index, ListViewItem listViewItem)
       at System.Windows.Forms.ListView.ListViewItemCollection.Add(ListViewItem listViewItem)
       at MyNamespace.MyListView.Fill(IEnumerable`1 data)

Some times I get an exception like this:

System.ArgumentOutOfRangeException was unhandled
  Message="Specified argument was out of the range of valid values.\r\nParameter name: index"
  StackTrace:
       at System.Windows.Forms.ListViewItem.ListViewSubItem.Actualize(Int32 index)
       at System.Windows.Forms.ListViewItem.ListViewSubItemCollection.Actualize()
       at System.Windows.Forms.ListView.ListViewItemCollection.Insert(Int32 index, ListViewItem listViewItem)
       at System.Windows.Forms.ListView.ListViewItemCollection.Add(ListViewItem listViewItem)

No correct solution

OTHER TIPS

These two lines suggest me that could be a problem with the headers of the ListView, did you fill it or defined it before add the items?

   at System.Windows.Forms.ListView.ntvGetColumnHeaderWidth(Int32 iColumn)
   at System.Windows.Forms.ColumnHeader.get_Width()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top