2010-03-11 32 views
5

sigo recibiendo este error cuando intento llamar Encuentra()Error: ¿El método especificado no es compatible?

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

    } 

Editar:

me sale ese error al llamar método FINDTEXT de otra forma, por llamar a este método desde el formulario principal doesn' dar lugar a tal error.

+0

¿Cuál es su resultado esperado? – Anonymous

+0

Lo siento pero no entendí tu pregunta. Por favor, consulte mi edición. – DanSogaard

Respuesta

2

Depende de la fuente de datos subyacente qué operaciones admite. Creo que DataTable es el único que fuera de la caja es compatible con esto. Puede verificar (en este caso) a través de:

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

So; ¿Cuál es la fuente de datos subyacente? Un List<T> (o incluso BindingList<T>) no proporcionará esto.

Cuestiones relacionadas