Note that there are some explanatory texts on larger screens.

plurals
  1. POApplying a filter to a BindingSource, but it doesn't work
    primarykey
    data
    text
    <p>I have a TextBox, in which I put a phrase, which is either the description of a task or the id of a task. I want to filter a list using the text from this TextBox. But when I put text into this TextBox, filtering doesn't work, and the collection in the DataGridView doesn't change. </p> <p>What can be wrong?</p> <pre><code>public void BindData() { var emptyBindingSource = new BindingSource(); dataGridViewTaskList.AutoGenerateColumns = false; dataGridViewTaskList.DataSource = emptyBindingSource; var taskList = GetTasks(); _bindingSource = new BindingSource(); _bindingSource.DataSource=taskList.Response; dataGridViewTaskList.AutoGenerateColumns = false; dataGridViewTaskList.DataSource = _bindingSource.DataSource; if (dataGridViewTaskList.Columns["gridViewColumnId"] == null) dataGridViewTaskList.Columns.Add(new DataGridViewColumn() {Name = "gridViewColumnId"}); else dataGridViewTaskList.Columns["gridViewColumnId"].DataPropertyName = "Id"; if (dataGridViewTaskList.Columns["gridViewColumnDescription"] == null) dataGridViewTaskList.Columns.Add(new DataGridViewColumn() {Name = "gridViewColumnDescription"}); else dataGridViewTaskList.Columns["gridViewColumnDescription"].DataPropertyName = "Description"; } private void tbSearchedPhraseOrId_TextChanged(object sender, EventArgs e) { _bindingSource.Filter = string.Format("Id = '{0}'", tbSearchedPhraseOrId.Text); } </code></pre> <p>I added the following in BindData method and it doesn't work either:</p> <pre><code>_bindingSource.Filter = string.Format("Id LIKE '%{0}%'", "23"); </code></pre> <p>Designer:</p> <pre><code>this.dataGridViewTaskList.AllowUserToAddRows = false; this.dataGridViewTaskList.AllowUserToDeleteRows = false; this.dataGridViewTaskList.AllowUserToOrderColumns = true; this.dataGridViewTaskList.AllowUserToResizeRows = false; this.dataGridViewTaskList.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.dataGridViewTaskList.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; this.dataGridViewTaskList.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; this.dataGridViewTaskList.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataGridViewTaskList.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.gridViewColumnId, this.gridViewColumnDescription}); this.dataGridViewTaskList.Location = new System.Drawing.Point(6, 62); this.dataGridViewTaskList.MultiSelect = false; this.dataGridViewTaskList.Name = "dataGridViewTaskList"; this.dataGridViewTaskList.ReadOnly = true; this.dataGridViewTaskList.RowHeadersVisible = false; this.dataGridViewTaskList.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; this.dataGridViewTaskList.Size = new System.Drawing.Size(414, 488); this.dataGridViewTaskList.TabIndex = 0; </code></pre>
    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.
    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