Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GridView Filter #4

Open
frahman2 opened this issue Jul 9, 2017 · 6 comments
Open

GridView Filter #4

frahman2 opened this issue Jul 9, 2017 · 6 comments
Assignees

Comments

@frahman2
Copy link

frahman2 commented Jul 9, 2017

Hi

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

@desarrollo03TR
Copy link

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

@manhag
Copy link

manhag commented Dec 19, 2017

any updates 👍 ?

@dquinter
Copy link

dquinter commented Apr 3, 2018

Hi all

Yes, any updates about this?

Thanks 👍

@Cocotteseb Cocotteseb self-assigned this Aug 20, 2018
@AngeloCresta
Copy link

Anyone on this?
Thanks!

@AngeloCresta
Copy link

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants