Krypton-OutlookGrid icon indicating copy to clipboard operation
Krypton-OutlookGrid copied to clipboard

GridView Filter

Open frahman2 opened this issue 7 years ago • 6 comments

Hi

Great Job, Please it will be great to see a possibility of filtering that grid.

frahman2 avatar Jul 09 '17 06:07 frahman2

I'm trying to add filter support using Advanced GridView (https://github.com/davidegironi/advanceddatagridview) but it is not working.

desarrollo03TR avatar Jul 10 '17 15:07 desarrollo03TR

any updates 👍 ?

manhag avatar Dec 19 '17 10:12 manhag

Hi all

Yes, any updates about this?

Thanks 👍

dquinter avatar Apr 03 '18 18:04 dquinter

Anyone on this? Thanks!

AngeloCresta avatar Sep 23 '19 19:09 AngeloCresta

Hi, I know that it's a very old topic but I've managed to add Advanced GridView capabilities to the OutlookGrid. I've used a rude approach, by filtering using the filterstring updated from Advanced GridView control.

Outlookgrid has to inherit from "Advanced GridView" and the datasource has to be a DataTable and passed twice:

            //get datasource
            DataTable books = new DataTable();
            books.ReadXml(Application.StartupPath + @"\Data\Books.xml");

            OutlookGrid1.DataSource = books;
            OutlookGrid1.BaseDataTable = books;

in the constructor of the Outlookgrid I've added a property and an event listner: new property: public object BaseDataTable { get; set; }

in constructor add: this.FilterStringChanged += ModernOutlookGrid_FilterStringChanged;

and the sub:

        bool blurredFilter = false;
        private void ModernOutlookGrid_FilterStringChanged(object sender, FilterEventArgs e)
        {
            //Debug.WriteLine(this.FullFilterString);

            if ((!string.IsNullOrEmpty(FullFilterString) && BaseDataTable != null) || blurredFilter)
            {
                //ClearEverything();

                dataSource.Rows.Clear();
                Rows.Clear();

                DataView dvWorking = ((DataTable)BaseDataTable).DefaultView;
                dvWorking.RowFilter = FullFilterString;


                foreach (DataRow r in dvWorking.ToTable().Rows)
                {
                    OutlookGridRow row = new OutlookGridRow();

                    //create row structure
                    row.CreateCells(this);

                    //populate cells
                    for (int i = 0; i < Columns.Count; i++)
                    {
                        row.Cells[i].Value = r[i].ToString();
                    }

                    dataSource.Rows.Add(row);
                }

                Fill();

                blurredFilter = true;
            }
        }

in the "Advanced GridView" control I've added this property:

        private string fullFilterString = string.Empty;
        public string FullFilterString
        {
            get { return fullFilterString; }
        }

and modified the funcion BuildFilterString() in this way:

        #region "   Filter Events   "
        /// <summary>
        /// Build the complete Filter string
        /// </summary>
        /// <returns></returns>
        private string BuildFilterString()
        {
            StringBuilder sb = new StringBuilder("");
            String sbExt = "";
            string appx = "";

            foreach (string filterOrder in filterOrderList)
            {
                DataGridViewColumn Column = Columns[filterOrder];

                if (Column != null)
                {
                    ColumnHeaderCell cell = Column.HeaderCell as ColumnHeaderCell;
                    if (cell != null)
                    {
                        if (cell.FilterAndSortEnabled && cell.ActiveFilterType != MenuStrip.FilterType.None)
                        {
                            sb.AppendFormat(appx + "(" + cell.FilterString + ")", Column.DataPropertyName);

                            sbExt = sbExt + appx + ("(" + cell.FilterString + ")").Replace("{0}", Column.HeaderText).Replace("Convert([", "").Replace("],System.String)", "");
                            appx = " AND ";
                        }
                    }
                }
            }

            fullFilterString = sbExt;

            return sb.ToString();
        }

As I said, It was rude and for sure not elegant, but it's ok for my needs.. Hope this helps Angelo OutlookgridAdv

AngeloCresta avatar Feb 15 '24 14:02 AngeloCresta

with the same approach (using the sortstring) I've integrated the sort too... and fixed the filter for dates Angelo

AngeloCresta avatar Feb 15 '24 19:02 AngeloCresta