Ejemplo n.º 1
0
 private void TxtExistDt()
 {
     if (!this.Focused && !DgvEx.Focused)
     {
         DgvEx.Hide();
         if (this.Text.Trim().Length > 0 && thisText.Length > 0)
         {
             string strWhere = DgvDataSourceWhere.Replace("@keyword", thisText);
             strWhere = strWhere.Replace("like", "=").Replace("%", "");
             DataRow[] drs = ((DataTable)DgvDataSource).Select(strWhere);
             if (drs.Length <= 0)
             {
                 MessageBox.Show("输入不正确!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 this.Focus();
                 this.SelectAll();
             }
         }
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// tab按下验证
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 internal void TextBoxDplDgv_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
 {
     if (e.KeyCode == Keys.Tab)
     {
         DgvEx.Hide();
         if (this.Text.Trim().Length > 0)
         {
             string strWhere = DgvDataSourceWhere.Replace("@keyword", this.Text.Trim());
             strWhere = strWhere.Replace("like", "=").Replace("%", "");
             DataRow[] drs = ((DataTable)DgvDataSource).Select(strWhere);
             if (drs.Length <= 0)
             {
                 MessageBox.Show("输入不正确!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 this.Focus();
                 this.SelectAll();
             }
         }
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 绑定显示
        /// </summary>
        internal void DgvExShow(object sender, EventArgs e)
        {
            //如果没绑数据则不显示
            if (DgvDataSource == null)
            {
                if (txtdgv_dataBinds != null)
                {
                    txtdgv_dataBinds(sender, e);
                }
                else
                {
                    return;
                }
            }
            try
            {
                if (DgvDataSource == null)
                {
                    return;
                }

                this.dgvForm       = this.FindForm();
                DgvForm.KeyPreview = true;

                DataTable dt = new DataTable();
                dt = ((DataTable)DgvDataSource).Clone();

                ////添加对文本框为焦点时过滤%  pwg 20140506
                string txtwhere = "";
                if (this.Text.Trim().Contains("%"))
                {
                    int indesif = this.Text.Trim().IndexOf("%");
                    int length  = this.Text.Trim().Length;
                    if (indesif != 0 && length > 1 && indesif + 1 < length)
                    {
                        txtwhere = this.Text.Trim().Replace("%", "");
                    }
                }
                else
                {
                    txtwhere = this.Text.Trim();
                }

                string strWhere = DgvDataSourceWhere.Replace("@keyword", txtwhere);

                DataRow[] drs = ((DataTable)DgvDataSource).Select(strWhere);

                int row = 0;
                foreach (DataRow dr in drs)
                {
                    row++;
                    if (row == ShowRowCount)
                    {
                        break;
                    }
                    dt.ImportRow(dr);
                }

                DgvEx.TabIndex = this.TabIndex;

                DgvX = 0;
                DgvY = 0;
                controlParent(this);

                //DgvX = this.Location.X;
                //DgvY=this.Location.Y;
                DgvEx.Location = new Point(DgvX, DgvY + this.Height);

                //DgvEx.Location = this.FindForm().PointToClient(this.PointToScreen(new Point(-2, this.Height)));

                Size size = DgvForm.Size;
                if (wValue >= (size.Width - DgvX))
                {
                    wValue = (size.Width - DgvX) - 15;
                }
                if (hValue >= (size.Height - (DgvY + this.Height)))
                {
                    hValue = (size.Height - (DgvY + this.Height)) - 15;
                }

                DgvEx.Size = new System.Drawing.Size(WValue, HValue);

                DgvEx.Parent = this.Parent;

                DgvEx.BringToFront();

                DgvEx.DataSource = null;

                DgvEx.DataSource = dt;

                string[] indexs = VisibleIndexs.Split(',');
                foreach (string index in indexs)
                {
                    int a;
                    if (int.TryParse(index, out a))
                    {
                        DgvEx.Columns[a].Visible = false;
                    }
                }

                float widths = 0;

                DgvEx.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;


                for (int i = 0; i < DgvEx.Columns.Count; i++)
                {
                    if (DgvEx.Columns[i].Visible)
                    {
                        widths += DgvEx.Columns[i].GetPreferredWidth(DataGridViewAutoSizeColumnMode.AllCells, true); // 计算调整列后单元列的宽度和
                    }
                }

                if (widths >= DgvEx.Size.Width - 7)                                       // 如果调整列的宽度大于设定列宽
                {
                    DgvEx.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; // 调整列的模式 自动
                }
                //else
                //    DgvEx.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; // 如果小于 则填充



                Cursor.Current = Cursors.Default;

                DgvEx.Show();
                this.Focus();
                BindTextBoxDplDgvToForm();
            }
            catch (Exception ex)
            {
                //throw new Exception(ex.Message);
                MessageBox.Show(ex.Message);
            }
        }