Filtering DataGridView without changing datasource

前端 未结 7 1818
渐次进展
渐次进展 2020-11-22 06:55

I\'m developing user control in C# Visual Studio 2010 - a kind of \"quick find\" textbox for filtering datagridview. It should work for 3 types of datagridview datasources:

7条回答
  •  渐次进展
    2020-11-22 07:30

    I have a clearer proposal on automatic search in a DataGridView

    this is an example

    private void searchTb_TextChanged(object sender, EventArgs e)
        {
            try
            {
                (lecteurdgview.DataSource as DataTable).DefaultView.RowFilter = String.IsNullOrEmpty(searchTb.Text) ?
                    "lename IS NOT NULL" :
                    String.Format("lename LIKE '{0}' OR lecni LIKE '{1}' OR ledatenais LIKE '{2}' OR lelieu LIKE '{3}'", searchTb.Text, searchTb.Text, searchTb.Text, searchTb.Text);
            }
            catch (Exception ex) {
                MessageBox.Show(ex.StackTrace);
            }
        }
    

提交回复
热议问题