My access database is shown in my datagridview.
When i start the program and click through the names everything is displayed in the linked textboxes.

But ones i search through my database, and the results are filtered.
My cellclick stops working, not getting any error messages.
It just stick to whatever i selected before i search through the DB.

Dani AI

Generated

The behavior described — CellClick works before a filter but then seems to “stick” on the old row — usually means the UI-update logic stopped running or is reading from the wrong view after the grid is filtered. later found that a section of the code responsible for populating the textboxes had been disabled, which is one of the most common causes.

Typical causes and quick checks:

  • Reassigning DataGridView.DataSource can detach or replace event handlers; confirm handlers are still attached after any rebind.
  • A guard/flag used to suppress updates during bulk operations may not be reset after filtering.
  • Code that indexes into the original DataTable (by numeric index) will be wrong after filtering; the grid shows a view, not the original row order.
  • Click handlers that do not check e.RowIndex >= 0 can silently do nothing when a header or an invalid row is involved.
  • Clearing selection after applying the filter will leave the UI showing old textbox values until a new selection is made.

Recommended, more-robust approaches (VB.NET):

  • Use a BindingSource between the DataTable and the DataGridView, and bind textboxes to the BindingSource so changes propagate automatically.
Dim bs As New BindingSource()
bs.DataSource = myDataTable
dataGridView.DataSource = bs
txtName.DataBindings.Add("Text", bs, "Name")
bs.Filter = "Name LIKE '%searchtext%'"
  • If manual copy is needed, read the DataRowView from the clicked row (this survives filtering):
Private Sub dgv_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgv.CellClick
    If e.RowIndex < 0 Then Return
    Dim drv As DataRowView = CType(dgv.Rows(e.RowIndex).DataBoundItem, DataRowView)
    txtName.Text = drv("Name").ToString()
End Sub

Prefer reacting to BindingSource.CurrentChanged or DataGridView.SelectionChanged when updates must happen for programmatic or filtered changes. As noted, sharing the minimal bind/filter/event code speeds diagnosis when problems persist.

Can you post your code?

Sorry just noticed my mistake, had a part of the code turn of which filled the textboxes.

Guess i need some coffee to wake up haha.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.