Exemple #1
0
        public frmPopUpSimpleList(Container_HelperWPFDataGrid container)
        {
            this.Container = container;
            InitializeComponent();
            MyGrid.ItemsSource = container.Data;

            //possible todo: try to figure out initial form position in screen and size
            this.Width  = 300;
            this.Height = 300;
            Closing    += OnWindowClosing;
        }
Exemple #2
0
        private static DataGridColumn GetGridColumn(string columnName, Container_HelperWPFDataGrid container, DataGrid dataGrid)
        {
            var parameter = container.ColumnsInGrid.Where(x => x.FieldName == columnName).FirstOrDefault();

            foreach (DataGridColumn columnInGrid in dataGrid.Columns)
            {
                string gridColumnName = columnInGrid.Header.ToString();
                if (parameter.FieldName == gridColumnName)
                {
                    return(columnInGrid);
                }
            }

            return(null);
        }
Exemple #3
0
        /// <summary>
        /// Change column headers
        /// </summary>
        /// <param name="container"></param>
        /// <param name="dataGrid"></param>
        public static void SetColumnHeaders(Container_HelperWPFDataGrid container, DataGrid dataGrid)
        {
            foreach (DataGridColumn columnInGrid in dataGrid.Columns)
            {
                string gridColumnName = columnInGrid.Header.ToString();
                bool   found          = false;

                foreach (ColumnParametertInGrid setupColumn in container.ColumnsInGrid)
                {
                    if (gridColumnName == setupColumn.FieldName)
                    {
                        found = true;
                        columnInGrid.Header = setupColumn.FieldHeader;
                        break;
                    }
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// Changee the order of displayed columns
        /// </summary>
        /// <param name="container"></param>
        /// <param name="dataGrid"></param>
        public static void ChangeColumnOrder(Container_HelperWPFDataGrid container, DataGrid dataGrid)
        {
            int columnIndex = 0;

            foreach (ColumnParametertInGrid setupColumn in container.ColumnsInGrid)
            {
                foreach (DataGridColumn columnInGrid in dataGrid.Columns)
                {
                    string gridColumnName = columnInGrid.Header.ToString();
                    if (gridColumnName == setupColumn.FieldName)
                    {
                        columnInGrid.DisplayIndex = columnIndex;
                        columnIndex++;
                        break;
                    }
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// Send grid and columns and it will sort by default. Example (column): "col1;asc,col2;desc,col3;asc"
        /// </summary>
        public static void ShowOrHideColumns(Container_HelperWPFDataGrid container, DataGrid dataGrid)
        {
            foreach (DataGridColumn columnInGrid in dataGrid.Columns)
            {
                string gridColumnName = columnInGrid.Header.ToString();
                bool   found          = false;

                foreach (ColumnParametertInGrid setupColumn in container.ColumnsInGrid)
                {
                    if (gridColumnName == setupColumn.FieldName)
                    {
                        columnInGrid.IsReadOnly = !setupColumn.UserCanEdit;
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    columnInGrid.Visibility = Visibility.Collapsed;
                }
            }
        }
Exemple #6
0
        /// <summary>
        /// Send grid and columns and it will sort by default. Example (column): "col1;asc,col2;desc,col3;asc"
        /// </summary>
        /// <param name="dataGrid"></param>
        /// <param name="columns"></param>
        public static void SortGrid(string columnsToSort, Container_HelperWPFDataGrid container, DataGrid dataGrid)
        {
            foreach (var col in dataGrid.Columns)
            {
                col.SortDirection = null;
            }

            var colToSort = columnsToSort.Split(',');

            // Clear current sort descriptions
            dataGrid.Items.SortDescriptions.Clear();

            foreach (string column in colToSort)
            {
                var               aux       = column.Split(";");
                string            fieldName = aux[0];
                string            sortDirectionFromParam = aux[1];
                ListSortDirection sortDirection          = ListSortDirection.Ascending;
                if (sortDirectionFromParam.ToLower() == "asc")
                {
                    sortDirection = ListSortDirection.Ascending;
                }
                else
                {
                    sortDirection = ListSortDirection.Descending;
                }

                DataGridColumn dataGridColumn = GetGridColumn(fieldName, container, dataGrid);

                var sortDescription = new SortDescription(dataGridColumn.SortMemberPath, sortDirection);
                // Add the new sort description
                dataGrid.Items.SortDescriptions.Add(sortDescription);
            }

            // Refresh items to display sort
            dataGrid.Items.Refresh();
        }