I have got the following error message when I'm trying to search things from Datagridview using MyDataGridview as a DataTable shown below:
the error:
Object reference not set to an instance of an object.
The Search Code:
private void txtSearch_TextChanged(object sender, EventArgs e)
{
DataTable dt = new DataTable();
string filterField = "pname";
dt = (DataTable)dgvpd.DataSource;
dt.DefaultView.RowFilter = string.Format("[{0}] LIKE '%{1}%'", filterField, txtSearch.Text);
}
The error message points on this line
dt.DefaultView.RowFilter = string.Format("[{0}] LIKE '%{1}%'", filterField, txtSearch.Text);