alec

alec

  • NA
  • 86
  • 49.3k

datagridviewcheckboxcolumn problem getting value

Dec 9 2011 7:03 AM
I'm sure everyone has had enough of my posts but these datagridviews are giving me so much hassle! I have three of them that are used for data collection to do a filtered search of a database. each one has two columns left is a list of manufactures, suppliers or categories the right is checkbox column and I have the code below that is used to form a string of all the entries on the left who were checked in the right column. but it fails and says "object reference not set to an instance of an object"

//manufacturer filter used as example
                    if (checkBoxManufacturerFilter.Checked == true) //this combobox isn't in the table its just to indicate weather this filter should be applyed or not
                    {
                        if (FirstFilter == false)
                        {
                            FilteredSearchQuery = FilteredSearchQuery + "and ";
                        }

                        string ManufacturerList = string.Empty;
                        foreach (DataGridViewRow row in DGVmanufacturerFilter.Rows)
                        {
                            if ((bool)row.Cells[1].Value == true) 
                            {
                                ManufacturerList = ManufacturerList + "," + (string)row.Cells[0].Value;
                            }
                        }

                        if (ManufacturerList.Length > 0)
                        {
                            if (ManufacturerList.Substring(0, 1) == ",")
                            {
                                ManufacturerList = ManufacturerList.Substring(1);
                            }
                        }

                        ManufacturerList = "(" + ManufacturerList + ")";
                        string ManufacturerFilterClause = "manufacturer in " + ManufacturerList + " ";
                        FilteredSearchQuery = FilteredSearchQuery + ManufacturerFilterClause;

                        if (FirstFilter == true)
                        {
                            FirstFilter = false;
                        }
                    }

Answers (1)