Here is the situation I am inserting rows into a datagridview and then using a function to group similar rows together based on a column.
When I call to compare the lastrow with the current row the application passes the information that should be equal. i.e 479 ST-Vieurtur
as the "Destinatio n" with the call below:
if (!ColumnEqual(L astSourceRow[Field.FieldName], SourceRow[Field.FieldName]))
When the comparison function is called, a and b look exactly alike but are said to be false.
the pattern is that I am using a loop to add the rows to the datagrid based on a quantity selected. i.e. street name | Address | # of packages
if they say 3 packages I insert three rows of quantity 1 with the streetname and address.
Then they do the same thing repeatedly until they want to merge the orders.
the pattern I can see is that when it hits the second group of addresses even if it is the same it evaluates false.
Below is the comparison function can anyone shed some light please!!
the second group alwasy
private bool ColumnEqual(obj ect a, object b)
{
/*
* Compares two values to see if they are equal. Also compares DBNULL.Value.
*
* Note: If your DataTable contains object fields, you must extend this
* function to handle them in a meaningful way if you intend to group on them.
*/
if ((a is DBNull) && (b is DBNull))
return true; //both are null
if ((a is DBNull) || (b is DBNull))
return false; //only one is null
return (a == b); //value type standard comparison
}
When I call to compare the lastrow with the current row the application passes the information that should be equal. i.e 479 ST-Vieurtur
as the "Destinatio n" with the call below:
if (!ColumnEqual(L astSourceRow[Field.FieldName], SourceRow[Field.FieldName]))
When the comparison function is called, a and b look exactly alike but are said to be false.
the pattern is that I am using a loop to add the rows to the datagrid based on a quantity selected. i.e. street name | Address | # of packages
if they say 3 packages I insert three rows of quantity 1 with the streetname and address.
Then they do the same thing repeatedly until they want to merge the orders.
the pattern I can see is that when it hits the second group of addresses even if it is the same it evaluates false.
Below is the comparison function can anyone shed some light please!!
the second group alwasy
private bool ColumnEqual(obj ect a, object b)
{
/*
* Compares two values to see if they are equal. Also compares DBNULL.Value.
*
* Note: If your DataTable contains object fields, you must extend this
* function to handle them in a meaningful way if you intend to group on them.
*/
if ((a is DBNull) && (b is DBNull))
return true; //both are null
if ((a is DBNull) || (b is DBNull))
return false; //only one is null
return (a == b); //value type standard comparison
}
Comment