Click here to Skip to main content
13,903,354 members
Rate this:
Please Sign up or sign in to vote.
See more:
How do i filter a datagridview using a combobox and textbox... so far I have this

        private void TypeSearch_TextChanged(object sender, EventArgs e)

            if (ItemcomboBox1.Text == "Barcode")
                (productionDGV.DataSource as DataTable).DefaultView.RowFilter = string.Format("Barcode LIKE '%{0}%'", TypeSearch.Text);

but I get an error message of ...
An unhandled exception of type 'System.NullReferenceException' occurred in monitoring and stock management.exe

Additional information: Object reference not set to an instance of an object.

I've tried debugging but I cant find it

What I have tried:

<pre>protected List<string> list = new List<string>();
F-ES Sitecore 18-May-18 5:20am
You're referencing something (using ".") that is null. It might be ItemcomboBox1, (productionDGV.DataSource as DataTable), DefaultView or TypeSearch. We can't run your code so we can't tell you which. You need to learn how to debug so you can at least find out what is null, and from there work out how to deal with it, and as we don't know what you're trying to do or what your business rules are we can't tell you that either.
Member 13765884 18-May-18 5:31am
hi, okay thank you. Its a piece of homework for school.
I will try to debug again. What do you mean by "you're referencing something (using ".") " I cannot find it in the code
F-ES Sitecore 18-May-18 6:04am
If you look at this line


You have


we say that "b" is referencing "a", so is a is null you will get the null reference exception. Anytime you have a.b, if "a" is null it will error.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web03 | 2.8.190306.1 | Last Updated 18 May 2018
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100