Ejemplo n.º 1
0
        /// <summary>
        /// Gets first selected object in the <code>UltraGrid</code>.
        /// </summary>
        /// <param name="grid">Target grid.</param>
        /// <param name="includeActiveRow">Indicates whether to include an active row when looking for selected objects.</param>
        /// <returns>First selected object in the <code>UltraGrid</code>.</returns>
        public static object GetSelectedObject(this UltraGrid grid, bool includeActiveRow = true)
        {
            if (grid == null)
            {
                _log.Error("Grid parameter is null.");
                throw new ArgumentNullException("grid");
            }

            if (grid.InvokeRequired)
            {
                object result = null;
                grid.Invoke(new MethodInvoker(() =>
                {
                    result = GetSelectedObject(grid, includeActiveRow);
                }));
                return(result);
            }

            if (grid.Selected.Rows.Count > 0 && grid.Selected.Rows[0].ListIndex >= 0)
            {
                return(grid.Selected.Rows[0].ListObject);
            }
            else if (includeActiveRow && grid.ActiveRow != null && grid.ActiveRow.Index >= 0)
            {
                return(grid.ActiveRow.ListObject);
            }
            return(null);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the list of selected objects in the <code>UltraGrid</code> optionally including the active row.
        /// </summary>
        /// <param name="grid">Target grid.</param>
        /// /// <param name="includeActiveRow">Indicates whether to include an active row when looking for selected objects.</param>
        /// <returns>First selected object in the <code>UltraGrid</code>.</returns>
        public static IList <object> GetSelectedObjectList(this UltraGrid grid, bool includeActiveRow = true)
        {
            if (grid == null)
            {
                _log.Error("Grid parameter is null.");
                throw new ArgumentNullException("grid");
            }

            if (grid.InvokeRequired)
            {
                IList <object> result = null;
                grid.Invoke(new MethodInvoker(() =>
                {
                    result = GetSelectedObjectList(grid, includeActiveRow);
                }));
                return(result);
            }

            var list = (grid.Selected.Rows.Cast <UltraGridRow>().Where(row => row.Index >= 0).Select(row => row.ListObject)).ToList();

            if (includeActiveRow && grid.ActiveRow != null && grid.ActiveRow.Index >= 0 && !list.Contains(grid.ActiveRow.ListObject))
            {
                list.Add(grid.ActiveRow.ListObject);
            }
            return(list);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Set format on all columns in grid witch certain data type.
        /// </summary>
        /// <param name="grid">Grid whose columns will be formatted.</param>
        /// <param name="columnDataType">Data type of columns which will be formatted.</param>
        /// <param name="format">Column format to apply.</param>
        public static void SetColumnFormat(this UltraGrid grid, Type columnDataType, string format)
        {
            if (grid.InvokeRequired)
            {
                grid.Invoke(new MethodInvoker(() => SetColumnFormat(grid, columnDataType, format)));
                return;
            }

            _log.DebugFormat("Setting column format to {0} for all column of type {1} ...", format, columnDataType);
            if (grid == null)
            {
                throw new ArgumentNullException("grid", "Grid is null.");
            }
            else if (string.IsNullOrWhiteSpace(format) || string.IsNullOrEmpty(format))
            {
                throw new ArgumentException("Format is empty.");
            }
            else if (columnDataType == null)
            {
                throw new ArgumentNullException("columnDataType", "Column data type is null.");
            }
            else if (grid.DisplayLayout.Bands.Count == 0)
            {
                _log.WarnFormat("Unable to set format on columns because grid has no bands.");
                return;
            }

            foreach (var band in grid.DisplayLayout.Bands)
            {
                foreach (var column in band.Columns)
                {
                    if (column.DataType == columnDataType)
                    {
                        column.Format = format;
                    }
                }
            }
            _log.DebugFormat("Setting column format complete.");
        }
Ejemplo n.º 4
0
        /// <summary>
        /// resized all columns in the grid to fit the contents.
        /// </summary>
        /// <param name="grid">Grid on which the resize is performed.</param>
        /// <param name="resizeType">Type of resize.</param>
        public static void ResizeColumnsToFit(this UltraGrid grid, PerformAutoSizeType resizeType = PerformAutoSizeType.AllRowsInBand)
        {
            if (grid == null)
            {
                _log.Error("Grid parameter is null.");
                throw new ArgumentNullException("grid");
            }

            if (grid.InvokeRequired)
            {
                grid.Invoke(new MethodInvoker(() => ResizeColumnsToFit(grid, resizeType)));
            }
            else
            {
                _log.Debug("Resizing grid to fit ...");
                foreach (var column in grid.DisplayLayout.Bands[0].Columns)
                {
                    column.PerformAutoResize(resizeType, true);
                }
                _log.Debug("Resizing grid complete.");
            }
        }