Faced such a problem. As if everything works, click on any value in the DataGridView, and it automatically appears in TextBox through DataBings, for further editing. But when I find a value in a DataGridView through a search, it already stops displaying in TextBoxes. What's my mistake ?
Here is the search code:
private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)13) { if (string.IsNullOrEmpty(textBox1.Text)) { dataGridView1.DataSource = serijospakavimoprotokolasBindingSource; } else { var query = from o in serijospakavimoprotokolasBindingSource.DataSource as List<Serijos_pakavimo_protokolas> where o.Serijos_Nr == textBox1.Text.Trim() || o.Serijos_Nr.Contains(textBox1.Text) || o.Pavadinimas.Contains(textBox1.Text) || o.Pakuote == textBox1.Text || o.Serijos_dydis.Contains(textBox1.Text) select o; dataGridView1.DataSource = query.ToList(); } } } Update
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.Entity; using System.Data.Entity.Infrastructure; using System.Data.SqlClient; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApplication11 { public partial class Form1 : Form { SVF_ProtokolaiEntities serija; public Form1() { InitializeComponent(); } private void bntNew_Click(object sender, EventArgs e) //New insert { try { tabControl1.Enabled = true; textBox15.Focus(); Serijos_pakavimo_protokolas c = new Serijos_pakavimo_protokolas(); serija.Serijos_pakavimo_protokolas.Add(c); serijospakavimoprotokolasBindingSource.Add(c); serijospakavimoprotokolasBindingSource.MoveLast(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void btnEdit_Click(object sender, EventArgs e) //edit { tabControl1.Enabled = true; textBox15.Focus(); } private void btnCancel_Click(object sender, EventArgs e) //cancel edit { tabControl1.Enabled = false; serijospakavimoprotokolasBindingSource.ResetBindings(false); foreach (DbEntityEntry entry in serija.ChangeTracker.Entries()) { switch (entry.State) { case EntityState.Added: entry.State = EntityState.Detached; break; case EntityState.Modified: entry.State = EntityState.Unchanged; break; case EntityState.Deleted: entry.Reload(); break; } } } private void btnSave_Click(object sender, EventArgs e) //save { try { serijospakavimoprotokolasBindingSource.EndEdit(); serija.SaveChangesAsync(); tabControl1.Enabled = false; } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); serijospakavimoprotokolasBindingSource.ResetBindings(false); } } private void Form1_Load(object sender, EventArgs e) //Form { tabControl1.Enabled = false; serija = new SVF_ProtokolaiEntities(); serijospakavimoprotokolasBindingSource.DataSource = serija.Serijos_pakavimo_protokolas.ToList(); } private void dataGridView1_KeyDown(object sender, KeyEventArgs e) //del from grid { if (e.KeyCode == Keys.Delete) { if (MessageBox.Show("Ar tikrai norite ištrinti ?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { serija.Serijos_pakavimo_protokolas.Remove(serijospakavimoprotokolasBindingSource.Current as Serijos_pakavimo_protokolas); serijospakavimoprotokolasBindingSource.RemoveCurrent(); } } } private void textBox1_KeyPress(object sender, KeyPressEventArgs e) //search { if (e.KeyChar == (char)13) { if (string.IsNullOrEmpty(textBox1.Text)) { dataGridView1.DataSource = serijospakavimoprotokolasBindingSource; } else { var query = from o in serijospakavimoprotokolasBindingSource.DataSource as List<Serijos_pakavimo_protokolas> where o.Serijos_Nr == textBox1.Text.Trim() || o.Serijos_Nr.Contains(textBox1.Text) || o.Pavadinimas.Contains(textBox1.Text) || o.Pakuote == textBox1.Text || o.Serijos_dydis.Contains(textBox1.Text) select o; dataGridView1.DataSource = query.ToList(); } } } private void button1_Click(object sender, EventArgs e) //Eksporto mygtukas { Form2 fr2 = new Form2(); fr2.ShowDialog(); } private void btnSearch_Click(object sender, EventArgs e) { } private void button2_Click(object sender, EventArgs e) { } } } Before searching
After searching
Finds, but does not display.


List<T>take a collection that supports filtering, for example,DataTable. - Alexander Petrov