错误:不支持指定的方法?

Dan*_*ard 8 c# notsupportedexception

当我尝试调用Find()时,我不断收到此错误

public void findTxt(string text)
    {
        BindingSource src = new BindingSource();
        src.DataSource = dataGridView1.DataSource;
        src.Position = src.Find("p_Name", text);    // Specified method is not supported

        if (src.Position == 0 && dataGridView1.Rows[0].Cells[2].Value.ToString() == text)
        {
            MessageBox.Show("Item found!!");
            dataGridView1.CurrentCell = dataGridView1.Rows[src.Position].Cells[2];
        }
        else if (src.Position == 0 && dataGridView1.Rows[0].Cells[2].Value.ToString() != text)
        {
            MessageBox.Show("Item not found!!");
        }
        else
        {
            MessageBox.Show("Item found!!");
            dataGridView1.CurrentCell = dataGridView1.Rows[src.Position].Cells[2];
        }

    }
Run Code Online (Sandbox Code Playgroud)

编辑:

从另一个表单调用findText方法时出现错误,但是从主窗体调用此方法不会导致这样的错误.

Mar*_*ell 5

它支持什么操作取决于底层数据源。我相信这DataTable是唯一一个开箱即用的支持这一点的。您可以通过以下方式检查(在这种情况下):

IBindingListView blv = yourDataSource as IBindingListView;
bool canSearch = blv != null && blv.SupportsSearching;
Run Code Online (Sandbox Code Playgroud)

所以; 底层数据源是什么?A List<T>(甚至BindingList<T>)不会提供这个。