//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;
}
}
Sam HobbsPosted Dec 9, 2011, 2:40 PM
I will guess. It is a very common mistake to not check for the new row row; the row at the bottom that is for adding a new row. So in other words before using "row.Cells[1]" first check to see if row.Index == DGVmanufacturerFilter.NewRowIndex.
If that is not the problem and solution, then please tell us at least what source code line is getting the error.