Esempio n. 1
0
        //选择列的选择事件
        protected virtual void ComboBoxColumns_SelectedValueChanged(object sender, EventArgs e)
        {
            ComboBox dgvFilterHostCom = sender as ComboBox;

            if (dgvFilterHostCom.DataSource == null)
            {
                return;
            }

            DgvBaseColumnFilter baseColumn = new DgvBaseColumnFilter();

            if (dgvFilterHostCom.SelectedValue is KeyValuePair <DgvBaseColumnFilter, string> )
            {
                baseColumn = ((KeyValuePair <DgvBaseColumnFilter, string>)dgvFilterHostCom.SelectedValue).Key;
            }
            else if (dgvFilterHostCom.SelectedValue is DgvBaseColumnFilter)
            {
                baseColumn = dgvFilterHostCom.SelectedValue as DgvBaseColumnFilter;
            }

            var oSelectedValue = baseColumn.DataGridViewColumn.DataPropertyName;
            var iFilterIndex   = GetFilterIndexByFilterName(oSelectedValue);

            if (iFilterIndex == -1)
            {
                return;
            }
            SetCurrentFilterIndex(iFilterIndex);
        }
Esempio n. 2
0
        protected override void OnColumnRemoved(DataGridViewColumnEventArgs e)
        {
            try
            {
                if (mColumnFilterList == null)
                {
                    return;
                }

                mColumnFilterList.RemoveAll(k => k == null);
                DgvBaseColumnFilter dgvBaseCol = mColumnFilterList.Find(k => k.DataGridViewColumn == e.Column);

                if (dgvBaseCol != null)
                {
                    mColumnFilterList.Remove(dgvBaseCol);
                }
            }
            catch (Exception)
            {
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ColumnFilterEventArgs"/> class.
 /// </summary>
 /// <param name="Column">The DstaGridView column.</param>
 /// <param name="ColumnFilter">The column filter instance.</param>
 public ColumnFilterEventArgs(DataGridViewColumn Column, DgvBaseColumnFilter ColumnFilter)
 {
     this.mColumn       = Column;
     this.mColumnFilter = ColumnFilter;
     this.mHandled      = Handled;
 }
Esempio n. 4
0
        private void CreateColumnFilter(DataGridViewColumn c)
        {
            if (!mAutoCreateFilters)
            {
                return;
            }
            //Raise the event about column filter creation

            DgvBaseColumnFilter baseColFilter = new DgvBaseColumnFilter();

            switch (c.GetType().Name)
            {
            case "DataGridViewComboBoxColumn":
                baseColFilter = new DgvComboBoxColumnFilter();
                break;

            case "DataGridViewCheckBoxColumn":
                baseColFilter = new DgvCheckBoxColumnFilter();
                break;

            case "DataGridViewTextBoxColumn":
                baseColFilter = new DgvTextBoxColumnFilter();

                if (_DataSourceView.Table != null &&
                    _DataSourceView.Table.Columns[c.DataPropertyName].DataType == typeof(DateTime))
                {
                    baseColFilter = new DgvDateColumnFilter();
                }
                break;
            }

            ColumnFilterEventArgs e = new ColumnFilterEventArgs(c, baseColFilter);

            if (ColumnFilterAdding != null)
            {
                ColumnFilterAdding(this, e);
            }
            mColumnFilterList.Insert(c.Index, e.ColumnFilter);

            if (e.ColumnFilter != null)// == null when non-data column
            {
                if (ColumnFilterAdded != null)
                {
                    ColumnFilterAdded(this, e);
                }

                e.ColumnFilter.Init(this, _DataSourceView, c.Index);

                ContextMenuStrip    oMenuStrip = new ContextMenuStrip();
                MyToolStripMenuItem oToolAscding, oToolDescending, oToolFilter, oToolFilterDelete;

                oToolAscding =
                    new MyToolStripMenuItem("升序", ((System.Drawing.Image)(resources.GetObject("Sort_Ascending"))),
                                            new EventHandler(mMenuStripSort_Click));
                oToolAscding.Name          = "toolscriptmenuitemasc";
                oToolAscding.DgvBaseColumn = e.ColumnFilter;
                oToolAscding.Size          = new System.Drawing.Size(213, 22);
                oToolAscding.SortDirection = ListSortDirection.Ascending;
                oMenuStrip.Items.Add(oToolAscding);

                oToolDescending =
                    new MyToolStripMenuItem("降序", ((System.Drawing.Image)(resources.GetObject("Sort_Descending"))),
                                            new EventHandler(mMenuStripSort_Click));
                oToolDescending.Name          = "toolscriptmenuitemdesc";
                oToolDescending.DgvBaseColumn = e.ColumnFilter;
                oToolDescending.Size          = new System.Drawing.Size(213, 22);
                oToolDescending.SortDirection = ListSortDirection.Descending;
                oMenuStrip.Items.Add(oToolDescending);

                oToolFilter =
                    new MyToolStripMenuItem("过滤", ((System.Drawing.Image)(resources.GetObject("Filter_Add"))),
                                            new EventHandler(mMenuStripFilter_Click));
                oToolFilter.Name          = "toolscriptmenuitemFilter";
                oToolFilter.DgvBaseColumn = e.ColumnFilter;
                oMenuStrip.Items.Add(oToolFilter);

                oToolFilterDelete =
                    new MyToolStripMenuItem("取消过滤", ((System.Drawing.Image)(resources.GetObject("Filter_Delete"))),
                                            new EventHandler(mMenuStripFilterDelete_Click));
                oToolFilterDelete.Name          = "toolscriptmenuitemFilterDelete";
                oToolFilterDelete.DgvBaseColumn = e.ColumnFilter;
                oMenuStrip.Items.Add(oToolFilterDelete);

                c.HeaderCell.ContextMenuStrip = oMenuStrip;
            }

            if (mColumnFilterList == null)
            {
                FilterHost.ComboBoxColumns.DataSource = null;
                return;
            }

            Dictionary <DgvBaseColumnFilter, string> dicCombox = new Dictionary <DgvBaseColumnFilter, string>();

            foreach (DgvBaseColumnFilter oCol in mColumnFilterList)
            {
                dicCombox.Add(oCol, oCol.OriginalDataGridViewColumnHeaderText);
            }

            BindingSource bs = new BindingSource();

            bs.DataSource = dicCombox;

            FilterHost.ComboBoxColumns.DataSource    = bs;
            FilterHost.ComboBoxColumns.ValueMember   = "Key";
            FilterHost.ComboBoxColumns.DisplayMember = "Value";
        }