9

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];
        }

    }

編集:

別のフォームからfindTextメソッドを呼び出すとそのエラーが発生しますが、メインフォームからこのメソッドを呼び出すと、そのようなエラーにはなりません。

4

2 に答える 2

4

どの操作をサポートするかは、基礎となるデータソース次第です。すぐに使用できるのDataTableはこれだけだと思います。次の方法で(この場合)確認できます。

IBindingListView blv = yourDataSource as IBindingListView;
bool canSearch = blv != null && blv.SupportsSearching;

そう; 基礎となるデータソースは何ですか? A List<T>(またはBindingList<T>) はこれを提供しません。

于 2010-03-11T04:57:07.743 に答える