Exemplo n.º 1
0
        void PopupControl_Selected(GridViewPopupEventArgs e)
        {
            if (e == null)
            {
                this.DataGridView.EndEdit();
                if (this.ColumnIndex < this.DataGridView.CurrentRow.Cells.Count - 1)
                {
                    var nextCell = this.DataGridView.CurrentRow.Cells[this.ColumnIndex + 1];
                    nextCell.Selected             = true;
                    this.DataGridView.CurrentCell = nextCell;
                }
                return;
            }

            //txtPopup.EditingControlFormattedValue = display;
            this.Value = e.Value;

            if (e.IsClosed)
            {
                this.DataGridView.EndEdit();
                if (this.OwningColumn.DisplayIndex < this.DataGridView.CurrentRow.Cells.Count - 1)
                {
                    var nextCell = this.DataGridView.CurrentRow
                                   .Cells.Cast <DataGridViewCell>()
                                   .Where(x => x.Displayed && x.OwningColumn.DisplayIndex > this.OwningColumn.DisplayIndex)
                                   .OrderBy(x => x.OwningColumn.DisplayIndex)
                                   .FirstOrDefault();
                    if (nextCell != null)
                    {
                        nextCell.Selected             = true;
                        this.DataGridView.CurrentCell = nextCell;
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void SetDisplayValue(GridViewPopupEventArgs e)
        {
            if (e == null)
            {
                return;
            }

            e.Display = this.SelectedText;
            e.Value   = this.SelectedValue;
        }
Exemplo n.º 3
0
        /// <summary>
        /// 根据选中行,读取记录表中的行号和数据,排除多选的情况
        /// </summary>
        /// <param name="popupEvent"></param>
        private GridViewPopupEventArgs SetPopupEvent(int keyIndex)
        {
            GridViewPopupEventArgs popupEvent = new GridViewPopupEventArgs(this);

            switch (dataType)
            {
            case DataEnum.DataTable:
            case DataEnum.DataRows:
            {
                var item = currentPageRowSource.Skip(keyIndex - 1).FirstOrDefault();
                popupEvent.RowIndex  = _dataRowSource.IndexOf(item);
                popupEvent.RowSource = item;
            }
            break;

            case DataEnum.BaseModel:
            {
                var item = currentPageModelSource.Skip(keyIndex - 1).FirstOrDefault();
                popupEvent.RowIndex  = _dataModelSource.IndexOf(item);
                popupEvent.RowSource = item;
            }
            break;

            default:
                break;
            }

            if (!MultiSelect) //单选
            {
                SelectedIndexs.Clear();
                SelectedIndexs.Add(popupEvent.RowIndex);
            }
            else //多选
            {
                //不存在时,选中状态,否则无响应
                if (!SelectedIndexs.Contains(popupEvent.RowIndex))
                {
                    SelectedIndexs.Add(popupEvent.RowIndex);
                }
                else
                {
                    SelectedIndexs.Remove(popupEvent.RowIndex);
                }
            }
            popupEvent.SelectedIndexs = SelectedIndexs;

            return(popupEvent);
        }
Exemplo n.º 4
0
        void PopupControl_Selected(GridViewPopupEventArgs e)
        {
            if (e == null)
            {
                return;
            }

            this.Data = e.Value;
            this.Text = e.Display;
            isChanged = true;

            if (e.IsClosed)
            {
                FocusHelper.FocusNext(this, false);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 处理键盘操作等信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Right)
            {
                PageIndex++;
                DataBind();
                e.Handled = true;
            }
            else if (e.KeyCode == Keys.Left)
            {
                PageIndex--;
                DataBind();
                e.Handled = true;
            }
            else if (e.KeyCode == Keys.Enter)
            {
                if (this.MultiSelect && this.SelectedIndexs.Count >= 1)
                {
                    if (this.Selected != null)
                    {
                        GridViewPopupEventArgs popupEvent = new GridViewPopupEventArgs(this)
                        {
                            SelectedIndexs = this.SelectedIndexs
                        };
                        SetDisplayValue(popupEvent);
                        //不存在时,选中状态,否则无响应
                        this.Selected(popupEvent);
                    }
                }
                else if (this.dataGridView1.CurrentRow != null)
                {
                    int keyIndex = this.dataGridView1.CurrentRow.Index + 1;
                    if (this.Selected != null)
                    {
                        var popupEvent = SetPopupEvent(keyIndex);

                        if (!MultiSelect) //单选
                        {
                            SetDisplayValue(popupEvent);
                            this.Selected(popupEvent);
                            EnterString = "";
                        }
                        else //多选
                        {
                            SetDisplayValue(popupEvent);
                            //不存在时,选中状态,否则无响应
                            this.Selected(popupEvent);
                        }
                    }
                }
                this.Close();
            }
            else if (e.KeyCode == Keys.Escape)
            {
                this.Close();
                if (this.MultiSelect)
                {
                    if (this.Selected != null)
                    {
                        this.Selected(null);
                    }
                }
            }
            else if (e.KeyCode == Keys.Back) //删除键
            {
                if (EnterString.Length > 0)  //当多选时,删除选择项,删空时退出
                {
                    EnterString = EnterString.Substring(0, EnterString.Length - 1);
                    PageIndex   = 1;
                    this.DataBind();
                }
                else
                {
                    var popupEvent = new GridViewPopupEventArgs(this);
                    if (this.SelectedIndexs.Count > 0)
                    {
                        this.SelectedIndexs.RemoveAt(this.SelectedIndexs.Count - 1);
                        this.DataBind();
                        popupEvent.IsClosed = false;
                    }
                    else
                    {
                        this.Close();
                    }
                    if (this.Selected != null)
                    {
                        popupEvent.SelectedIndexs = this.SelectedIndexs;
                        SetDisplayValue(popupEvent);
                        this.Selected(popupEvent);
                    }
                }
            }
        }