Beispiel #1
0
        /// <summary>
        /// Shows the popup.
        /// </summary>
        /// <param name="ColumnIndex">Index of the column.</param>
        public void ShowPopup(int ColumnIndex)
        {
            if (mColumnFilterList[ColumnIndex] == null)
            {
                return;                                         // non-data column
            }
            int OldColumnIndex = mCurrentColumnIndex;

            mCurrentColumnIndex = ColumnIndex;
            Rectangle r = mDataGridView.GetCellDisplayRectangle(ColumnIndex, -1, false); // get the header size info

            FilterHost.CurrentColumnFilter = mColumnFilterList[ColumnIndex];
            try
            {
                //use "try" because old column could have been removed
                mDataGridView.InvalidateCell(OldColumnIndex, -1);
            }
            catch (Exception)
            {
            }
            ColumnFilterEventArgs e = new ColumnFilterEventArgs(mDataGridView.Columns[ColumnIndex], mColumnFilterList[ColumnIndex]);

            if (PopupShowing != null)
            {
                PopupShowing(this, e);
            }
            if (!e.Handled)
            {
                FilterHost.Popup.Show(mDataGridView, r.X + r.Width - 4, r.Y - 10);             // show the filterhost popup near the column
            }
            FilterHost.Popup.Focus();

            mDataGridView.InvalidateCell(mCurrentColumnIndex, -1);  // Force header repaint (to show a selection yellow frame)
        }
Beispiel #2
0
        private void CreateColumnFilter(DataGridViewColumn c)
        {
            if (!mAutoCreateFilters)
            {
                return;
            }
            //Raise the event about column filter creation
            ColumnFilterEventArgs e = new ColumnFilterEventArgs(c, null);

            if (ColumnFilterAdding != null)
            {
                ColumnFilterAdding(this, e);
            }
            //if not provided, by an event handler, proceed with standard filter creation
            if (e.ColumnFilter == null)
            {
                Type DataType = null;
                if (c.DataPropertyName != "")
                {
                    DataType = mBoundDataView.Table.Columns[c.DataPropertyName].DataType;

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

                    case "DataGridViewCheckBoxColumn":
                        e.ColumnFilter = new DgvCheckBoxColumnFilter();
                        break;

                    case "DataGridViewTextBoxColumn":
                        if (DataType == typeof(DateTime))
                        {
                            e.ColumnFilter = new DgvDateColumnFilter();
                        }
                        else
                        {
                            e.ColumnFilter = new DgvTextBoxColumnFilter();
                        }
                        break;

                    case "DataGridViewImageColumn":
                        e.ColumnFilter = new DgvComboBoxImageColumnFilter();
                        break;
                    }
                }
            }
            mColumnFilterList[c.Index] = e.ColumnFilter;
            if (e.ColumnFilter != null)   // == null when non-data column
            {
                if (ColumnFilterAdded != null)
                {
                    ColumnFilterAdded(this, e);
                }
                e.ColumnFilter.Init(this, FilterHost, c, mBoundDataView);
            }
        }