コード例 #1
0
        private void OpenWindowExcecute()
        {
            if (PreviewSelect != null)
            {
                var arg = new PreviewSelectEventArgs();
                PreviewSelect(this, arg);

                if (arg.Cancel == true)
                {
                    ClearLookup();
                    return;
                }
            }

            LoadData();

            if (valueColumnPropInfo == null || idColumnPropInfo == null)
            {
                ClearLookup();
                return;
            }

            PrepareLookupWindow();

            if (SelectionMode == LookupSelectionMode.Single)
            {
                lookupWindow.ShowDialog();
            }
            else
            {
                if (ItemsSource == null || ItemsSource.Count() == 0)
                {
                    ClearLookup();
                    return;
                }
                else
                {
                    foreach (var item in ItemsSource)
                    {
                        if (!(item is ISelectable))
                        {
                            return;
                        }
                        break;
                    }
                }

                if (SelectedIndices != null)
                {
                    foreach (var item in SelectedItems)
                    {
                        (item as ISelectable).IsSelected = true;
                    }
                }

                if (lookupWindow.ShowDialog() == true)
                {
                    var itemList  = new List <object>();
                    var indexList = new List <int>();
                    var idList    = new List <int>();
                    int counter   = -1;
                    foreach (var item in ItemsSource)
                    {
                        counter++;
                        if ((item as ISelectable).IsSelected)
                        {
                            indexList.Add(counter);
                            itemList.Add(item);
                            var id = idColumnPropInfo?.GetValue(item) as int?;
                            if (id != null)
                            {
                                idList.Add(id.Value);
                            }
                        }
                    }

                    if (itemList.Count > 0)
                    {
                        ChangeSource    = ChangeSourceEnum.FromComponent;
                        SelectedItems   = itemList;
                        SelectedIndices = indexList;
                        SelectedIds     = idList;
                        ChangeSource    = ChangeSourceEnum.None;
                    }
                    else
                    {
                        ClearLookup();
                    }
                }
            }
        }
コード例 #2
0
ファイル: TreeLookup.cs プロジェクト: hossein-abdn/Infra.Wpf
        private void OpenWindowExcecute()
        {
            if (PreviewSelect != null)
            {
                var arg = new PreviewSelectEventArgs();
                PreviewSelect(this, arg);

                if (arg.Cancel == true)
                {
                    ClearLookup();
                    return;
                }
            }

            LoadData();

            if (valueColumnPropInfo == null || idColumnPropInfo == null)
            {
                ClearLookup();
                return;
            }

            PrepareLookupWindow();

            if (SelectionMode == LookupSelectionMode.Single)
            {
                treeLookupWindow.ShowDialog();
            }
            else
            {
                if (ItemsSource == null)
                {
                    ClearLookup();
                    return;
                }

                if (SelectedItems != null)
                {
                    foreach (var item in SelectedItems)
                    {
                        if (item is ISelectable)
                        {
                            (item as ISelectable).IsSelected = true;
                        }
                    }
                }

                if (treeLookupWindow.ShowDialog() == true)
                {
                    if (typeof(ISelectable).IsAssignableFrom(ResultType))
                    {
                        var itemList = new List <object>();
                        var idList   = new List <int>();

                        var list = FlatItemsSource.Cast <ISelectable>().Where(x => x.IsSelected);
                        foreach (var item in list)
                        {
                            itemList.Add(item);
                            var id = idColumnPropInfo?.GetValue(item) as int?;
                            if (id != null)
                            {
                                idList.Add(id.Value);
                            }
                        }

                        if (itemList.Count > 0)
                        {
                            ChangeSource  = ChangeSourceEnum.FromComponent;
                            SelectedItems = itemList;
                            SelectedIds   = idList;
                            ChangeSource  = ChangeSourceEnum.None;
                        }
                        else
                        {
                            ClearLookup();
                        }
                    }
                }
            }
        }