I want to search data from datagridview by search text box double click the result to fill the textboxes in parent form

43 views Asked by At

I'm working on windows form application using C# .NET framework 4.8

Someone implemented code experience answer this.

Error System.NullReferenceException: 'Object reference not set to an instance of an object.'

(dgvRegistration.DataSource as DataTable).DefaultView.RowFilter = 
   string.Format("RegID='{0}'",txtSearch.Text);

Error: System.NullReferenceException: 'Object reference not set to an instance of an object.'

DataTable dataTable = (dgvRegistration.DataSource as DataTable);
dataTable.DefaultView.RowFilter = string.Format("RegID LIKE '{0}%'", txtSearch.Text);

Error: System.InvalidCastException: 'Unable to cast object of type 'System.Data.DataView' to type 'System.Data.DataSet'.'

DataSet dataSet = (DataSet)dgvRegistration.DataSource;
DataTable dt = ((DataView)dgvRegistration.DataSource).Table;
dt.DefaultView.RowFilter = string.Format("RegID LIKE '{0}%'", txtSearch.Text);
dataSet = (DataSet)(dgvRegistration.DataSource);

dgvRegistration.Refresh();

I want to search data from DataGridView by search text box, double click the result to fill the textboxes in parent form.

Also I can search any thing or any data like a dynamic search from DataGridView control.

0

There are 0 answers