Note that there are some explanatory texts on larger screens.

plurals
  1. POFiltering a BindingSource based on the number of child rows
    text
    copied!<p>I'm working on my first little Database application where I use a typed <code>DataSet</code> and data binding:</p> <p><img src="https://i.stack.imgur.com/V4fBr.png" alt="enter image description here"></p> <p>I have a <code>customersBindingSource</code> to bind the list of customers to the <code>ListBox</code> on the left and an <code>allowedclientsBindingSource</code> to bind the list of allowed clients (of the selected customer) to the <code>DataGridView</code> on the right.</p> <p>Now I'd like to apply a filter so that only disabled clients are shown on the right. I can do that by setting </p> <pre><code>allowedclientsBindingSource.Filter = "Enabled = 'false'"; </code></pre> <p>and this works fine. Now not all customers have disabled clients. And I want to show only those customers on the left which actually have disabled clients. So I'm looking for something like this:</p> <pre><code>customersBindingSource.Filter = "numberOfAllowedClients &gt; 0"; </code></pre> <p>Of course this <code>numberOfAllowedClients</code> must refer to the <em>filtered</em> list of allowed clients.</p> <p>What is the correct filter expression to achieve this?</p> <p><strong>Edit:</strong></p> <p>If possible I'd like to keep using data binding and not filling the <code>ListBox</code> manually.</p> <p>What I found is that I can filter the customers list based on the number of child rows like this:</p> <pre><code>customersBindingSource.Filter = "Count(Child.AllowedClientID) &gt; 0"; </code></pre> <p>but it uses the unfiltered list of clients. I also tried:</p> <pre><code>customersBindingSource.Filter = "Count(Child.Enabled = 'false') &gt; 0"; </code></pre> <p>but this doesn't work since no expressions are allowed in the <code>Count</code> aggregate. I also tried to set the <code>RowFilter</code> property on the <code>DefaultView</code> of the data table instead of on the binding source. But that didn't work either.</p> <p>Is there really no clean and easy solution for this without doing it manually?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload