Beispiel #1
0
        //



        internal static void AddItemToListView(ListView listView, Guid classId)
        {
            if (listView != null && listView.Items != null)
            {
                InstancePickerDialog ciPicker = new InstancePickerDialog();
                ciPicker.ClassId       = classId;
                ciPicker.SelectionMode = SelectionMode.Multiple;

                if (listView.Items.Count > 0)
                {
                    ciPicker.SetPickedInstances((Collection <IDataItem>)listView.ItemsSource);
                }

                bool?result = ciPicker.ShowDialog();
                if (result != null && result == true)
                {
                    Collection <IDataItem> items = listView.ItemsSource as Collection <IDataItem>;
                    foreach (IDataItem item in ciPicker.RemovedInstances)
                    {
                        items.Remove(item);
                    }

                    foreach (IDataItem item in ciPicker.PickedInstances)
                    {
                        if (!items.Contains(item))
                        {
                            items.Add(item);
                        }
                    }
                }
            }
        }
Beispiel #2
0
        internal static void AddItemToListView(ListView listView, Guid classId)
        {
            if (listView != null && listView.Items != null)
            {
                /* NOTE: The use of the IDataItem and InstancePickerDialog interfaces here is not supported/documented.
                 * This interface may change in the future and no migration path is guaranteed by Microsoft.
                 */
                InstancePickerDialog ciPicker = new InstancePickerDialog();
                ciPicker.ClassId       = classId;
                ciPicker.SelectionMode = SelectionMode.Multiple;

                if (listView.Items.Count > 0)
                {
                    ciPicker.SetPickedInstances((Collection <IDataItem>)listView.ItemsSource);
                }

                bool?result = ciPicker.ShowDialog();
                if (result != null && result == true)
                {
                    Collection <IDataItem> items = listView.ItemsSource as Collection <IDataItem>;
                    foreach (IDataItem item in ciPicker.RemovedInstances)
                    {
                        items.Remove(item);
                    }
                    foreach (IDataItem item in ciPicker.PickedInstances)
                    {
                        if (!items.Contains(item))
                        {
                            items.Add(item);
                        }
                    }
                }
            }
        }