示例#1
0
        ListBoxItemExt GenerateListBoxItemExt(ExtType type, GridColumn colConfig)
        {
            ListBoxItemExt item = null;

            switch (type)
            {
            case ExtType.Add:
                item = new ListBoxItemExt(ExtType.Add);
                break;

            case ExtType.Remove:
                item = new ListBoxItemExt(ExtType.Remove);
                break;
            }
            var column = GetColumnByName(colConfig.Name);

            item.Content = column != null ? column.Header : null;
            if (!colConfig.IsHided)
            {
                item.RemoveItem += new EventHandler(item_RemoveItem);
                item.DataContext = item;
                item.ColWidth    = colConfig.Width.Value;
            }
            else
            {
                item.AddItem += new EventHandler(item_AddItem);
                item.ColWidth = column.ActualWidth;
            }
            item.Name = string.Format(this.m_listBoxItemName_Prefix, colConfig.Name);
            return(item);
        }
示例#2
0
        void item_RemoveItem(object sender, EventArgs e)
        {
            var item            = sender as ListBoxItemExt;
            var availableSource = m_availableColumnsListBox.ItemsSource as ObservableCollection <ListBoxItemExt>;
            var selectedSource  = m_selectedColumnsListBox.ItemsSource as ObservableCollection <ListBoxItemExt>;

            selectedSource.Remove(item);

            var newItem = new ListBoxItemExt(ExtType.Add);

            newItem.Content  = item.Content;
            newItem.ColWidth = item.ColWidth;
            newItem.Name     = item.Name;
            newItem.AddItem += new EventHandler(item_AddItem);
            availableSource.Add(newItem);

            m_lstSelectedColumns_SelectionChanged(null, null);
        }
示例#3
0
        void GenerateLeftListBoxItem()
        {
            this.m_availableColumns.Clear();
            this.m_selectedColumns.Clear();

            foreach (var col in this.OwningGrid.Columns)
            {
                if (col.Header == null)
                {
                    continue;
                }
                var colName = col.GetColumnName();

                ListBoxItemExt item = new ListBoxItemExt(ExtType.Add);
                item.Name     = string.Format(this.m_listBoxItemName_Prefix, colName);
                item.AddItem += new EventHandler(item_AddItem);
                item.ColWidth = col.ActualWidth;
                item.Content  = col.Header;
                m_availableColumns.Add(item);
            }
        }
示例#4
0
        internal void InitGridSettings()
        {
            if (this.OwningGrid.GridSettings != null && this.OwningGrid.GridSettings.Count > 0)
            {
                var config = this.OwningGrid.GridSettings.FirstOrDefault(p => p.Name == RESET_NAME);
                if (config != null)
                {
                    this.OwningGrid.GridSettings.Remove(config);
                }
                GridSetting currentSetting = null;
                this.m_comboSettings.Items.Clear();
                this.OwningGrid.GridSettings.ForEach(p =>
                {
                    ComboBoxItem item = new ComboBoxItem {
                        Content = p.Name
                    };

                    if (p.IsDefault)
                    {
                        item.IsSelected     = true;
                        currentSetting      = p;
                        item.Content        = Default_Prefix + p.Name;
                        this.m_txtName.Text = p.Name;
                    }
                    this.m_comboSettings.Items.Add(item);
                });
                //如果数据库中没有Default的配置,则取第一个(此种情况会在Delete default config后出现)
                if (currentSetting == null)
                {
                    this.m_comboSettings.SelectedIndex = 0;
                    this.m_txtName.Text = this.OwningGrid.GridSettings[0].Name;
                    currentSetting      = this.OwningGrid.GridSettings[0];
                }

                this.CurrentGridConfig      = currentSetting;
                this.m_chkDefault.IsChecked = currentSetting.IsDefault;
                var re = this.m_cmbPageSize.Items.FirstOrDefault(p =>
                {
                    return((p as ComboBoxItem).Content.ToString() == currentSetting.PageSize.ToString());
                });
                var index = this.m_cmbPageSize.Items.IndexOf(re);
                this.m_cmbPageSize.SelectedIndex = index;

                this.m_availableColumns.Clear();
                this.m_selectedColumns.Clear();

                //Edit by Hax 20100203
                this.OwningGrid.m_resetGridConfig.Columns.ForEach(p =>
                {
                    var colConfig = this.CurrentGridConfig.Columns.FirstOrDefault(q => q.Name == p.Name);
                    if (colConfig != null)
                    {
                        if (!colConfig.IsHided)
                        {
                            var item      = GenerateListBoxItemExt(ExtType.Remove, colConfig);
                            item.ColIndex = colConfig.Index;
                            this.m_selectedColumns.Add(item);
                        }
                        else
                        {
                            var item = GenerateListBoxItemExt(ExtType.Add, colConfig);
                            this.m_availableColumns.Add(item);
                        }
                    }
                    else
                    {
                        var item      = new ListBoxItemExt(ExtType.Add);
                        item.AddItem += new EventHandler(item_AddItem);
                        item.Name     = string.Format(this.m_listBoxItemName_Prefix, p.Name);

                        var column = GetColumnByName(p.Name);
                        if (column != null && column.Header != null)
                        {
                            item.ColWidth = column.ActualWidth;
                            item.Content  = column.Header;
                            this.m_availableColumns.Add(item);
                        }
                    }
                });

                var list = m_selectedColumns.ToList();
                list.Sort((x, y) =>
                {
                    if (x.ColIndex > y.ColIndex)
                    {
                        return(1);
                    }
                    else if (x.ColIndex == y.ColIndex)
                    {
                        return(0);
                    }
                    else
                    {
                        return(-1);
                    }
                });

                m_selectedColumns.Clear();

                list.ForEach(p => m_selectedColumns.Add(p));

                /*
                 * Comment by Hax--20100203
                 * 为了避免以后开发人员增加或删除xaml中DataGrid的Column,造成新增加的Column在AvailableColumn中显示不出来
                 * 修改为根据DataGrid的ResetColumns(开发时设置的Column)来产生AvailableColumn和SelectedItem,而不是根据CurrentGridConfig来生成
                 */

                //this.CurrentGridConfig.Columns.ForEach(p =>
                //{
                //    var column = GetColumnByName(p.Name);

                //    if (column != null)
                //    {
                //        if (!p.IsHided)
                //        {
                //            var item = GenerateListBoxItemExt(ExtType.Remove, p);
                //            this.m_selectedColumns.Add(item);
                //        }
                //        else
                //        {
                //            var item = GenerateListBoxItemExt(ExtType.Add, p);
                //            this.m_availableColumns.Add(item);
                //        }
                //    }
                //});
            }
            else
            {
                GenerateLeftListBoxItem();
                //GenerateDefaultConfig();
            }

            this.m_availableColumnsListBox.ItemsSource = this.m_availableColumns;
            this.m_selectedColumnsListBox.ItemsSource  = this.m_selectedColumns;
        }