Note that there are some explanatory texts on larger screens.

plurals
  1. POFiltering related data in a DataGridView
    primarykey
    data
    text
    <p>I have a <code>DataGridView</code> that pulls data from a couple tables similarly to <a href="https://stackoverflow.com/questions/5678326/showing-the-related-data-in-datagridview" title="Showing the related data in Datagridview">this</a> setup. It works great. Good post and answer. Continuing with the example in that post, I now want to create a filter that yields all transactions in the <code>DataGridView</code> that apply to a specific account by using a <code>LIKE</code> parameter on the account description.</p> <p>I have a solution by checking the accounts table for the description and obtaining the IDAccount value then using that value in the <code>DataGridView</code> filter, but I was hoping there would be a more automated way using bindings.</p> <p>Any ideas? Thank you for your suggestions.</p> <p><strong>Edit</strong>: Supposing I have a <code>TextBox</code> control called AccountDescriptionBox, I'd like to be able to do something like</p> <pre><code>dataGridView1.Filter = string.Format("{0} LIKE '{1}'", "IDAccount", AccountDescriptionBox.Text); </code></pre> <p>Obviously, this won't work as IDAccount is an integer, not a string. The solution I mention above is</p> <pre><code>string filter = string.Empty; Regex searchTerm = new Regex(Regex.Escape(AccountDescriptionBox.Text).Replace('\\', '.'), RegexOptions.IgnoreCase); var accts = from acct in dataSet1.Accounts let matches = searchTerm.Matches(acct.Description) where matches.Count &gt; 0 select acct.ID; for (int i; i &lt; accts.Count() - 1; i++) { filter += string.Format("IDAccount = {0} OR ",accts.ElementAt(i)); } filter += string.Format("IDAccount = {0}",accts.Last()); dataGridView1.Filter = filter; </code></pre> <p>This works, but is cumbersome. I'd rather do it through bindings if there's a way.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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