Example #1
0
        public void UpdateSelection(OptionValueChangedEventArgs e)
        {
            if (e == null)
            {
                return;
            }
            if (inUpdate)
            {
                return;
            }
//      if (!optionItem.IsAlive) {
//        return;
//      }

//      IOptionItem oi = (IOptionItem)optionItem.Target;
            object value = e.NewValue;

            if (value == OptionItem.VALUE_UNDEFINED)
            {
                //no change
                return;
            }
            try {
                inUpdate = true;
                //lock selection for the duration of our update
                selection.BeginValueUpdate();

                ICollection <IPropertyItemDescriptor <T> > descriptors;
                descriptors = selection.Selection;

                bool hasChanged = false;
                foreach (IPropertyItemDescriptor <T> descriptor in descriptors)
                {
                    //get the propertyItem from the current lookup
                    IPropertyMap map = descriptor.Properties;
                    if (map == null)
                    {
                        continue;
                    }

                    //get value from current selection item
                    IPropertyItem item   = map.GetEntry(virtualPropertyName);
                    IValueSetter  setter = item != null ? item.Setter : null;
                    if (setter == null || !setter.CanSet())
                    {
                        continue;
                    }
                    setter.SetValue(value);
                    hasChanged = true;
                }

                if (hasChanged)
                {
                    selection.UpdateSelectedItems();
                }
            } finally {
                selection.EndValueUpdate();
                inUpdate = false;
            }
        }