Filtering rows of datagridview with text_changed when no specific datasource is attached

43 Views Asked by At

Using the following code i can dynamicaly filter the rows of a datagridview that is connected with a datasource which is a datatable

Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
        DirectCast(DataGridView1.DataSource, DataTable).DefaultView.RowFilter = String.Format("userid like '%{0}%' or shortcut like '%{0}%' or command like '%{0}%'", TextBox1.Text)
    End Sub

When i tried to use the same in a datagridview which is not connected whith a specific datasource but its rows where populated by using a loop such ass DataGridView2.Rows.Add(....) i get an object reference is not an instance of an object

Why is this happening;

0

There are 0 best solutions below