Example #1
2
File: ws.cs Project: tofupl/Csharp
        public void DeleteSelectedRows(DevExpress.XtraGrid.Views.Grid.GridView view)
        {
            if (view == null || view.SelectedRowsCount == 0) return;

            DataRow[] rows = new DataRow[view.SelectedRowsCount];

            for (int i = 0; i < view.SelectedRowsCount; i++)
                rows[i] = view.GetDataRow(view.GetSelectedRows()[i]);

            view.BeginSort();

            try
            {
                foreach (DataRow row in rows)
                    row.Delete();
            }
            finally
            {
                view.EndSort();
            }
        }
Example #2
0
        private void DeleteFocusedRows(DevExpress.XtraGrid.Views.Grid.GridView view)
        {
            if (view.RowCount > 0 && view.IsValidRowHandle(view.FocusedRowHandle) && !view.IsNewItemRow(view.FocusedRowHandle))
            {
                view.BeginSort();
                try
                {
                    view.DeleteRow(view.FocusedRowHandle);

                }
                catch (Exception)
                {
                }
                view.EndSort();
            }
        }
Example #3
0
        public static void ConfigGridView(DevExpress.XtraGrid.Views.Grid.GridView gridView, string[] bestFitColumns = null, string[] invisibleColumns = null, bool readOnly = false, string[] readOnlyColumns = null, bool allowGroup = false, string[] groupColumns = null, bool merge = false, string[] mergeColumns = null, bool allowFilter = true, bool allowSort = true)
        {
            gridView.OptionsCustomization.AllowFilter = allowFilter;
            gridView.OptionsCustomization.AllowSort = allowSort;

            //AutoSizeColumn
            //gridView.BestFitColumns();

            if (bestFitColumns != null)
            {
                foreach (var column in bestFitColumns)
                {
                    gridView.Columns[column].BestFit();
                }
            }

            //Visible column
            if (invisibleColumns != null)
            {
                foreach (var column in invisibleColumns)
                {
                    gridView.Columns[column].Visible = false;
                }
            }

            //Readonly
            gridView.OptionsBehavior.ReadOnly = readOnly;

            if (!readOnly && readOnlyColumns != null)
            {
                foreach (var column in readOnlyColumns)
                {
                    gridView.Columns[column].OptionsColumn.ReadOnly = true;
                }
            }

            //group column
            gridView.OptionsCustomization.AllowGroup = allowGroup;

            if (groupColumns != null)
            {
                gridView.BeginSort();
                try
                {
                    gridView.ClearGrouping();
                    int index = 0;
                    foreach (var column in groupColumns)
                    {
                        gridView.Columns[column].GroupIndex = index++;
                    }
                }
                finally
                {
                    gridView.EndSort();
                }
            }

            //merge column
            gridView.OptionsView.AllowCellMerge = merge;

            if (mergeColumns != null)
            {
                for (int i = 0; i < gridView.Columns.Count; i++)
                {
                    gridView.Columns[i].OptionsColumn.AllowMerge = DevExpress.Utils.DefaultBoolean.False;
                }

                foreach (var column in mergeColumns)
                {
                    gridView.Columns[column].OptionsColumn.AllowMerge = DevExpress.Utils.DefaultBoolean.True;
                }
            }

            ReconfigGridView(gridView);
        }