Skip to content

Infragistics Community Forum / Desktop / Ultimate UI for Windows Forms / Refresh filter dropdown values on data updated

Refresh filter dropdown values on data updated

New Discussion
Alex McMahon
Alex McMahon asked on Nov 17, 2008 1:44 PM

I’ve got a WinGrid that updates the rows as the bound data is updated. I also have the filter row enabled. How do I refresh the filter drop down so that any new values are available to be filtered upon and removed ones are removed.

 

For example if each row represents a user and there is a column for ‘logged in’ if all users start with this value false then the filter dropdown should only have false. When a user has logged in and the data updated the filter drop down options should now include false.

Sign In to post a reply

Replies

  • 0
    Mike Saltzman
    Mike Saltzman answered on Sep 18, 2008 4:19 PM

    You do not have to do anything. The list is repopulated every time it drops down.

    Do you mean that the rows in the grid are being changes while the filter list is already dropped down? There's no way to "refresh" the list while it is already dropped down. You would have to close it and re-open it. 

    • 0
      Alex McMahon
      Alex McMahon answered on Sep 19, 2008 8:59 AM

      Mike, 

      Thanks for the reply. 

      Now that's interesting. Where is the list repopulated from? As it's definately not being populated with the right values.

       I don't mean while it's already open. I'm seeing the wrong values when I open the drop-down. Interestingly enough if I resize the column and then do the drop-down it updates to reflect the new values. Or if I click on a row in the grid first and then on the drop down it also updates. The grid is read-only and it's when the data it's bound to changes that the drop-down is not updated.

       I'll have a look at how we're doing the binding, perhaps we're doing something slightly odd.

      • 0
        Mike Saltzman
        Mike Saltzman answered on Sep 19, 2008 2:35 PM

        What's the data source? Are you seeing the actual rows in the grid update? It sounds to me like your data source is not notifying the grid that an update has taken place. The dropdown gets it's values from the actual data in the column of the grid. This should be the same data that is in the dat source – unless your data source is an IList and doesn't notify the grid of changes. 

      • 0
        Alex McMahon
        Alex McMahon answered on Sep 19, 2008 2:55 PM

         I am seeing the actual rows in the grid update, so I assume that the data source must be notifying the grid of changes. The data source is a System.Windows.Forms.BindingSource, that uses a    System.ComponentModel.BindingList<TItem> as it's DataSource, the BindingList is initialized from a List<TItem>. (Hope that chain made sense!). Then when one of the TItems is updated we replace the instance in the BindingSource with the new version. I didn't originally create this code… Does it look right to you? is there a 'better' way?

        Simplified versions of the 2 relevant methods are below.

        public

        void PopulateGrid(List<TItem> itemList)
        {
        BindingList<TItem> boundList = new BindingList<TItem>(itemList);
        gridBindingSource.DataSource = boundList;//This is of type BindingSource
        grid.DataSource = gridBindingSource;
        } 

        public

         void AddOrUpdateItem(TItem item)
        {
        int idx;
        if ((idx = gridBindingSource.IndexOf(item)) != -1)
        {
        //the item already exists in the list so replace it
        gridBindingSource[idx] = item;
        }
        else
        {
        //add the new item
        idx = gridBindingSource.Add(item);
        }
        }

      • 0
        Mike Saltzman
        Mike Saltzman answered on Sep 19, 2008 8:57 PM

         [quote user="fluxmunki"]I am seeing the actual rows in the grid update, so I assume that the data source must be notifying the grid of changes.[/quote]

        That's a good assumption, I would think. Unless your code is explicitly refreshing the grid or something like that. 

        The only other thing that comes to mind is that maybe you are handling the BeforeRowFilterDropDown or BeforeRowFilterDropDownPopulate events and modifying the list in your code. 

        If that's not the case, then I don't know what's going on. You might try updating to the latest Hot Fix if you don't already have it. If that does not help, then the only thing to do would be to try duplicating the issue in a small sample project and then you could  Submit an incident to Infragistics Developer Support. If they can see the problem, we should be able to get it resolved. 

      • 0
        Alex McMahon
        Alex McMahon answered on Sep 22, 2008 3:56 PM

        Thanks for the suggestion.I wasn't handling those events before, but adding a handler showed me something interesting. The events were only being triggered on the first expansion of the dropdown (until the dropdown lost focus again). I've updated to the latest version with hotfixes and have seen same behaviour. I've now created a simplified demo app that I've sent to Developer Support (CAS-06045-Z66K79).  

         I think what I'm after is either for the dropdown to repopulate every single time, or for a way to invalidate the dropdown's valuelist so that it is re-populated next time.

      • 0
        Mike Saltzman
        Mike Saltzman answered on Sep 23, 2008 3:45 PM

        The dropdown should populate every time you drop it down, I think. Either that or the grid may be optimizing it by tracking changes to the column and only re-populating the list when something has changed. Either way, it sounds like a bug to me, because the column IS changing in your case and the dropdown is still not re-populating. 

        If you have not already done so, you might want to update your incident with a link to this forum post, so the Dev Support folks can see what we've already covered here. 🙂

      • 0
        Alex McMahon
        Alex McMahon answered on Sep 25, 2008 1:18 PM

         Just to update the thread with the resolution. The issue was responded to by eventually being marked as "not a bug" with completely understandable reasoning. Something in the response made me think of a workaround:

        “This is correct
        behavior since we don't want to populate and re-populate the filter
        list every time it is dropped down, since this would be very
        inefficient for the vast majority of users. The Filter Cell
        specifically checks the count of the items in the ValueList when you
        drop it down. When you enter edit mode on the filter cell and drop down
        the list, it's empty, so it populates it and fires the
        BeforeRowFilterDropDownPopulate and BeforeRowFilterDropDown events. The
        second time you drop it down while it is still in edit mode, the count
        is greater than 0 and it deliberately does not fire the events of
        re-populate list. If it did, this would be very inefficient for the
        vast majority of customers whose values are not going to change while
        the filter cell is in the middle of being edited by a user.”

         

        My Workaround:

        When I update the data source I also iterate through the filter row in
        the grid clearing out all the valuelists so that all the dropdowns will
        be forced to refresh.

      • 0
        Aleksey
        Aleksey answered on Nov 17, 2008 11:02 AM

        Hi, Alex.

        Could you provide me with sample of code you used as workaround. I have the same problem.
        I have tried to use the means you told about.
        >>My Workaround:
        >>When I update the data source I also iterate through the filter row in the grid
        >>clearing out all the valuelists so that all the dropdowns will be forced to refresh.
        >>but nothing came out of it.
        I tried to iterate through the filter row in the grid like this:
                    if (grid_.Rows.FilterRow != null)
                    {
                        foreach (UltraGridFilterCell cell in grid_.Rows.FilterRow.Cells)
                        {
                            //cell.ValueList //tried to clear…
                        }
                    }
        but
        I see that cell.ValueList does not have the methods for
        clearing/removing its items and it is always null at this moment. I
        tried to call this code after binding new values to datasource.
        It sounds like the populating 'cell.ValueList' is performed on manually drop down a filter…

        Thanks in advance. Alex.

         

      • 0
        Alex McMahon
        Alex McMahon answered on Nov 17, 2008 11:32 AM

        Alex,

        This is the code I used. We've actually stopped doing this now as it's a bit of a workaround. What we now do is pre-populate the drop-down with all possible values (even if they're not currently displayed), so it never needs to update. This worked well for us as the list of possible values was based on an enum so was fixed.

         

               if (grid.Rows.FilterRow != null & grid.Rows.FilterRow.Cells != null)
              {
                foreach (UltraGridFilterCell cell in grid.Rows.FilterRow.Cells)
                {
                  ValueList values = cell.ValueListResolved as ValueList;
                  if (values != null)
                  {
                    values.ValueListItems.Clear();
                  }
                }
              }

        Hope that helps

      • 0
        Aleksey
        Aleksey answered on Nov 17, 2008 1:34 PM

        Alex, thanks for you quickly answering my question and your piece of code. I am going to try it.

        I have found the mean of doing it too. My solution is not elegant, but it works.

        if (grid_.Rows.FilterRow != null)
                        {
                            UltraGridCell cell = grid_.ActiveCell;

                            if (cell != null && cell.IsFilterRowCell)
                            {
                                bool needRestoreEditMode = cell.IsInEditMode;
                                cell.Activated = false;
                                cell.Activated = true;
                                if (needRestoreEditMode)
                                    grid_.PerformAction(UltraGridAction.EnterEditMode);
                            }
                        }

        Repopulating values will be performed only for active filter cell if it's needed.

        Alex. 

         

      • 0
        Alex McMahon
        Alex McMahon answered on Nov 17, 2008 1:44 PM

         Not a bad workaround! So the key is de-activating and re-activating the cell to force a refresh. probably a bit tidier than my way, as it's more focussed on the individual situation where the problem occurs. I'll store your method in the old brain box in case we need this functionality again!

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Alex McMahon
Favorites
0
Replies
12
Created On
Nov 17, 2008
Last Post
17 years, 4 months ago

Suggested Discussions

Created by

Created on

Nov 17, 2008 1:44 PM

Last activity on

Feb 19, 2026 2:38 PM