我试图在其中包含人员列表的数据网格视图上进行一些搜索。
,并且从studentListBindingSource
填充DGV
我尝试了以下代码,但始终会引发错误Object reference not set to an instance of an object
出什么问题了?
public partial class Form4 : Form
{
public Form4(BindingList<Student> studentList)
{
InitializeComponent();
studentListBindingSource.DataSource = studentList;
}
private void searchTextBox_TextChanged(object sender, EventArgs e)
{
(studentListDataGridView.DataSource as DataTable).DefaultView.RowFilter = string.Format("FirstName LIKE '%{0}%'", searchTextBox.Text);
}
}