ilterhan
ilterhan

Reputation: 1

Storing the ADGV Filter C# Form

I'm storing the ADGV filter in Properties.Settings (local cache) and trying to use it later. However, when I apply the saved filter, the other users' data doesn't appear. How can I prevent this?

bindingSourceAssignments.DataSource = ConvertToDataTable(cachedAssignments);
dgvAssignments.DataSource = bindingSourceAssignments;

string lastFilter = Properties.Settings.Default.LastFilter;
bindingSourceAssignments.Filter = lastFilter;
private void dgvAssignments_FilterStringChanged(object sender, EventArgs e)
{
    this.bindingSourceAssignments.Filter = this.dgvAssignments.FilterString;
    Properties.Settings.Default.LastFilter = this.dgvAssignments.FilterString;
    Properties.Settings.Default.Save();
}

I am developing a desktop application using .NET Framework 4.8 and the Advanced DataGridView component from NuGet. My goal is to save and retain filters so that when the filtering panel is reopened, users see the last applied filters.

Initially, all data loads correctly, and filtering works as expected. When I filter by the "Assigned By" column, all names (A, B, C, D, E) appear. For example, if I select only "A" and apply the filter, the other names remain visible but become unchecked, while only "A" stays checked. However, after restarting the application, the unchecked names disappear, and only "A" remains visible. What I need is for all names (A, B, C, D, E) to always be visible, regardless of the previous selection.

During debugging, I found that setting the filter to "" makes all names (A, B, C, D, E) reappear. However, when I apply the filter programmatically instead of updating it through the UI, it gets set as:
(Convert([AssignedByID], System.String) IN ('27')). This results in only "A" appearing, while the other values do not show up.

How can I ensure that all names remain visible in the filter panel even after restarting the application?

Before:

Before

After:

after

Upvotes: 0

Views: 18

Answers (0)

Related Questions