0

I am encountering an issue. I have a datagrid and it is loading from my database. I also implemented a textBox which would filter results from the datagrid but for some reason I am getting a NullReferenceException. Below is my code for this particular textBox:

 private void textBox2_TextChanged_1(object sender, EventArgs e)
    {


        (dataGridView1.DataSource as DataTable).DefaultView.RowFilter = string.Format("Item_Number LIKE '%{0}%'", textBox2.Text);
    }

Where am I going wrong?

I know what a NullReferenceException is I just do not see why I am getting it. This is not a duplicate of an existing NullreferenceException

Javy
  • 381
  • 2
  • 14
  • check if it's not dataGridView1 but a property of it's have null reference – Anirudha Gupta Aug 17 '17 at 02:24
  • @AnirudhaGupta no that is not it. I find this strange as I implemented this with another dataGrid. only difference is that I had a comboBox which loaded the table from my database to my dataGridView – Javy Aug 17 '17 at 02:26
  • @AdamNewman have you tried it with the comboBox? – Jevon Aug 17 '17 at 02:27
  • @Jevon I would rather not do that. This is a constant table I will be working with so pulling from the table would be good – Javy Aug 17 '17 at 02:28

0 Answers0