2010-03-11 85 views
5

我不斷收到這個錯誤,當我嘗試調用查找()錯誤:不支持指定的方法?

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方法時,但是調用此方法從主窗體沒有按」我得到這個錯誤不會導致這樣的錯誤。

+0

你期待的結果是什麼? – Anonymous 2010-03-11 05:02:28

+0

對不起,但我不明白你的問題。請參閱我的編輯。 – DanSogaard 2010-03-11 05:07:49

回答

2

它取決於底層的數據源支持哪些操作。我相信DataTable開箱即用的支持的唯一一款。你可以檢查(在這種情況下)通過:

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

所以;底層數據源是什麼? A List<T>(或甚至BindingList<T>)不會提供此。

相關問題