价值不在预期范围内

时间:2012-03-14 19:57:22

标签: silverlight selecteditem

很抱歉,如果这已被覆盖致死(我注意到这个措辞有近5,000次点击)但我没有找到类似于我的例子。

我在2个地方的同一代码体中得到错误:

  1. mygrid.SelectedItem = row.DataContext; (右键单击第一行,如果它不是%100可见)
  2. 以下是上述实际代码:

        void addMenu(DataGridRow row)
        {
            if (ctxMenu == null)
            {
                ctxMenu = new ContextMenu();
                ContextMenuTools.addMenuItem(ctxMenu, "Reschedule", true, mnu_Click);
                ContextMenuService.SetContextMenu(row, ctxMenu);
            }
    
            reschedItem = (Job)row.DataContext;
    
            try
            {
                dgrMemo.SelectedItem = reschedItem;
    
                ctxMenu.Tag = row;
                ctxMenu.IsOpen = true;
            }
            catch 
            {
                ctxMenu = null;
            }
        }
    
    1. 替换上述网格的集合中的元素
    2. e.g。

      int rpos = datasource.IndexOf(reschedItem);
      reschedItem = createAnewObj();
      datasource[rpos] = reschedItem; // error occurs here.....sometimes (not sure how to reproduce other than scroll the grid up and down selecting different rows and hitting the above code)
      

      我怀疑在两种情况下都与我的数据源集合对象有关,但是由于以下情况发生了异常(对于上面的第1点),我很难理解为什么:

      {System.ArgumentException: Value does not fall within the expected range.
         at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
         at MS.Internal.XcpImports.SetValue(IManagedPeerBase obj, DependencyProperty property, Double d)
         at MS.Internal.XcpImports.SetValue(IManagedPeerBase doh, DependencyProperty property, Object obj)
         at System.Windows.DependencyObject.SetObjectValueToCore(DependencyProperty dp, Object value)
         at System.Windows.DependencyObject.SetEffectiveValue(DependencyProperty property, EffectiveValueEntry& newEntry, Object newValue)
         at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)
      ...
      

0 个答案:

没有答案