Ejemplo n.º 1
0
        void InitUIByProfileData()
        {
            GridSetting grid = this.OwningGrid.GridSettings.FirstOrDefault(p => p.IsDefault);

            grid.Columns.Sort((p1, p2) => p1.Index.CompareTo(p2.Index));

            foreach (var column in this.OwningGrid.Columns)
            {
                var name = string.Empty;
                try
                {
                    name = DataGridAttached.GetHeader(column).ToString();
                }
                catch
                {
                    name = column.GetColumnName();
                }

                grid.Columns.FirstOrDefault(p => p.Name == column.GetColumnName()).DisplayName = name;
            }

            ObservableCollection <GridColumn> collectionSelected = new ObservableCollection <GridColumn>(grid.Columns.Where(p => !p.IsHided));

            collectionSelected.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(collectionSelected_CollectionChanged);
            ListBoxSelectedColumns.ItemsSource    = collectionSelected;

            ObservableCollection <GridColumn> collectionAvailable = new ObservableCollection <GridColumn>(grid.Columns.Where(p => p.IsHided));

            ListBoxAvailableColumns.ItemsSource = collectionAvailable;
        }
Ejemplo n.º 2
0
 void InitDataGrid()
 {
     this.DataGridExample.GridID = this.OwningGrid.GridID;
     this.DataGridExample.IsShowColumnsSelector = false;
     this.DataGridExample.NeedStoreColumns      = true;
     foreach (var col in OwningGrid.Columns)
     {
         if (col is DataGridTemplateColumn)
         {
             var colTemp = col as DataGridTemplateColumn;
             var newCol  = new DataGridTemplateColumn {
                 Width = colTemp.Width, Name = colTemp.Name, CellTemplate = colTemp.CellTemplate
             };
             DataGridAttached.SetHeader(newCol, DataGridAttached.GetHeader(colTemp));
             this.DataGridExample.Columns.Add(newCol);
         }
         else if (col is DataGridTextColumn)
         {
             var colTemp = col as DataGridTextColumn;
             var newCol  = new DataGridTextColumn {
                 Width = colTemp.Width, Name = colTemp.Name, Binding = new System.Windows.Data.Binding {
                     Converter = colTemp.Binding.Converter, ConverterParameter = colTemp.Binding.ConverterParameter, Mode = colTemp.Binding.Mode, Path = colTemp.Binding.Path
                 }
             };
             DataGridAttached.SetHeader(newCol, DataGridAttached.GetHeader(colTemp));
             this.DataGridExample.Columns.Add(newCol);
         }
     }
 }
Ejemplo n.º 3
0
        internal void CheckDataGridColumnChanged()
        {
            bool              isNeedChanged      = false;
            GridSetting       defaultGridSetting = this.OwningGrid.GridSettings.FirstOrDefault(p => p.IsDefault);
            List <GridColumn> columns            = UtilityHelper.DeepClone <List <GridColumn> >(defaultGridSetting.Columns);

            foreach (var col in columns)
            {
                var findResult = this.OwningGrid.Columns.FirstOrDefault(colTemp => colTemp.GetColumnName() == col.Name);
                if (findResult == null)
                {
                    isNeedChanged = true;
                    RemoveCol(col.Name);
                }
            }

            foreach (var col in this.OwningGrid.Columns)
            {
                var findResult = defaultGridSetting.Columns.FirstOrDefault(colTemp => col.GetColumnName() == colTemp.Name);
                if (findResult == null)
                {
                    isNeedChanged = true;
                    var name = string.Empty;
                    try
                    {
                        name = DataGridAttached.GetHeader(col).ToString();
                    }
                    catch
                    {
                        name = col.GetColumnName();
                    }
                    col.Visibility = Visibility.Collapsed;
                    this.DataGridExample.Columns[this.OwningGrid.Columns.IndexOf(col)].Visibility = Visibility.Collapsed;
                    AddCol(new GridColumn
                    {
                        ActualWidth = col.ActualWidth,
                        Width       = col.Width,
                        DisplayName = name,
                        Index       = col.DisplayIndex,
                        IsFreezed   = false,
                        IsHided     = true,
                        Name        = col.GetColumnName()
                    });
                }
            }
            if (isNeedChanged)
            {
                var allSettings = this.OwningGrid.AllGridSettings;
                allSettings.RemoveAll(k => k.GridGuid == this.OwningGrid.GridID);
                this.OwningGrid.GridSettings.ForEach(p =>
                {
                    allSettings.Add(p);
                });
                this.OwningGrid.m_userProfile.Set(GridKeys.KEY_UP_GRIDSETTINGS, allSettings, true);
            }
        }