Beispiel #1
0
 protected virtual void OnRowCellEditForEditing(GridRowCellEditEventArgs arg)
 {
     if (_RowCellEditForEditing != null)
     {
         _RowCellEditForEditing(this, arg);
     }
 }
Beispiel #2
0
        void grdCtlMain_BeforeContextMenuClick(object sender, MB.XWinLib.XtraGrid.GridControlExMenuEventArg arg)
        {
            if (arg.MenuType == MB.XWinLib.XtraGrid.XtraContextMenuType.Copy)
            {
                arg.Handled = true;

                dataCopy();
            }
            else if (arg.MenuType == MB.XWinLib.XtraGrid.XtraContextMenuType.Past)
            {
                arg.Handled = true;

                IDataObject data = Clipboard.GetDataObject();

                object ss = data.GetData(typeof(string));
                dataPast(ss.ToString());
            }
            else if (arg.MenuType == XtraContextMenuType.DataImport)
            {
                arg.Handled = true;
                dataImport();
            }
            else if (arg.MenuType == XtraContextMenuType.QuickInput)
            {
                arg.Handled = true;

                if (arg.Column != null)
                {
                    DevExpress.XtraGrid.Views.Grid.GridView gridView = gridViewMain;
                    if (arg.Column.OptionsColumn.AllowEdit && gridView.FocusedRowHandle >= 0)
                    {
                        var dre = MB.WinBase.MessageBoxEx.Question("是否决定以当前选择列的值进行快速填充");
                        if (dre != DialogResult.Yes)
                        {
                            return;
                        }

                        DataRow entity = gridView.GetDataRow(gridView.FocusedRowHandle);
                        object  val    = entity[arg.Column.FieldName];
                        if (val != null)
                        {
                            int count = gridView.RowCount;
                            for (int i = 0; i < count; i++)
                            {
                                DataRow dr = gridView.GetDataRow(i);
                                GridRowCellEditEventArgs cellarg = new GridRowCellEditEventArgs(dr, arg.Column);
                                cellarg.AllowEdit = arg.Column.OptionsColumn.AllowEdit;
                                OnRowCellEditForEditing(cellarg);
                                if (cellarg.AllowEdit)
                                {
                                    gridView.SetRowCellValue(i, arg.Column.FieldName, val);
                                }
                            }
                        }
                    }
                }
            }
        }
Beispiel #3
0
        void gridViewMain_CustomDrawCell(object sender, RowCellCustomDrawEventArgs e)
        {
            DataRow dr = gridViewMain.GetDataRow(e.RowHandle);
            GridRowCellEditEventArgs arg = new GridRowCellEditEventArgs(dr, e.Column);

            arg.AllowEdit = e.Column.OptionsColumn.AllowEdit;
            OnRowCellEditForEditing(arg);
            if (!arg.AllowEdit)
            {
                e.Appearance.BackColor = Color.WhiteSmoke;
            }

            if (gridViewMain.IsCellSelected(e.RowHandle, e.Column))
            {
                e.Appearance.BackColor = Color.FromArgb(0, 88, 176);
                e.Appearance.ForeColor = Color.White;
            }
        }
Beispiel #4
0
        void gridViewMain_CustomRowCellEditForEditing(object sender, CustomRowCellEditEventArgs e)
        {
            DataRow dr = gridViewMain.GetDataRow(e.RowHandle);
            GridRowCellEditEventArgs arg = new GridRowCellEditEventArgs(dr, e.Column);

            arg.AllowEdit = e.Column.OptionsColumn.AllowEdit;
            OnRowCellEditForEditing(arg);

            bool canEdit = arg.AllowEdit;

            e.RepositoryItem.ReadOnly     = !canEdit;
            e.RepositoryItem.AllowFocused = canEdit;
            e.RepositoryItem.AppearanceReadOnly.BackColor   = canEdit ? Color.White : Color.WhiteSmoke;
            e.RepositoryItem.AppearanceReadOnly.BorderColor = canEdit ? Color.White : Color.WhiteSmoke;
            if (!canEdit)
            {
                SendKeys.Send("{TAB}");
            }
        }
Beispiel #5
0
        //数据粘贴
        private void dataPast(string clipboardData)
        {
            if (string.IsNullOrEmpty(clipboardData))
            {
                return;
            }

            string[] rows = System.Text.RegularExpressions.Regex.Split(clipboardData, "\r\n");

            if (rows == null || rows.Length == 0)
            {
                return;
            }
            List <string[]> copyDatas = new List <string[]>();
            int             colCount  = 0;

            //分析并获取需要复制的数据
            foreach (string line in rows)
            {
                if (string.IsNullOrEmpty(line))
                {
                    continue;
                }

                string[] cols = System.Text.RegularExpressions.Regex.Split(line, "\t");
                if (colCount < cols.Length)
                {
                    colCount = cols.Length;
                }

                copyDatas.Add(cols);
            }
            checkAllowPast(copyDatas.Count, colCount);
            GridCell[] cells     = gridViewMain.GetSelectedCells();
            int        rowIndex  = -1;
            int        colIndex  = -1;
            int        oldHandle = -1;

            foreach (GridCell cell in cells)
            {
                if (oldHandle != cell.RowHandle)
                {
                    colIndex = 0;
                    rowIndex++;

                    oldHandle = cell.RowHandle;
                }
                else
                {
                    colIndex++;
                }
                //判断对应的列是否允许编辑
                if (cell.Column.OptionsColumn.ReadOnly)
                {
                    continue;
                }

                if (copyDatas[rowIndex].Length < colIndex)
                {
                    continue;
                }

                string temp = copyDatas[rowIndex][colIndex];
                try {
                    DataRow dr = gridViewMain.GetDataRow(cell.RowHandle);
                    GridRowCellEditEventArgs cellarg = new GridRowCellEditEventArgs(dr, cell.Column);
                    cellarg.AllowEdit = cell.Column.OptionsColumn.AllowEdit;
                    OnRowCellEditForEditing(cellarg);
                    if (cellarg.AllowEdit)
                    {
                        object val = MB.Util.MyReflection.Instance.ConvertValueType(cell.Column.ColumnType, temp);
                        gridViewMain.SetRowCellValue(cell.RowHandle, cell.Column, val);
                    }
                }
                catch (MB.Util.APPException appex) {
                    throw appex;
                }
                catch (Exception ex) {
                    throw new MB.Util.APPException(ex.Message, MB.Util.APPMessageType.DisplayToUser);
                }
            }
        }