Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1284
Comparing values in Two grids and setting the forecolor color of the rows.
posted

Hi

  I am working on a .NET 2.0 project using UltraWingrid. I have 2 grids on my Form. I am using 2 different Datasets to bind them.

I want to compare the values in the first grid with the values in the second grid and show the difference as follows:

For example:

GRID1

 

 

ROLL No

NAME

CITY

1

A

AA

2

B

BB

3

C

CC

4

D

DD

5

E

EE

 

 

 

GRID2

 

 

ROLL No

NAME

CITY

1

A

AA

2

B

BB

6

F

FF

7

G

GG

=>If both Grid1 and Grid2 has same values in all the cells in a Row i dont want to highlight

=>If Grid1 record not found in Grid2 then the Forecolor of that record in Grid1 should be in green.

=>If Grid2 record  not found in Grid1 then the forecolor of that record in Grid2 should be in red.

How to achieve this without looping through the grid?

Thanks

Ashok

 

  • 37774
    posted

    I don't see how this could be accomplished without either looping through both grids, or having some sort of search mechanism on your data source so that you can quickly check to see if a certain value exists or not.  I suppose that one approach might be to incorporate the filtering functionality of the grid to search the data source, but this would still involve looping through each row in the grid.  For example:

    try
    {
        this.grid2.BeginUpdate();
        foreach (UltraGridRow row in this.grid1.Rows)
        {
            ColumnFiltersCollection columnFilters = this.grid2.DisplayLayout.Bands[0].ColumnFilters;
            string compareValue = row.Cells[0].Value.ToString();
            columnFilters[0].FilterConditions.Add(FilterComparisionOperator.Equals, compareValue);
            if (this.grid2.Rows.GetFilteredInNonGroupByRows().Length > 0)
            {
                // The value exists in the second grid, so we change the appearance
            }
            else
            {
                // The value doesn't exist in the second grid
            }
            columnFilters[0].ClearFilterConditions();
        }
    }
    finally
    {
        this.grid2.EndUpdate();
    }

    If you're trying to do a two-way comparison, you would have to do the same process, but searching through grid1 for all the rows in grid2.  As I mentioned, this still involves looping through the grid, though, but it does limit some of the loops that you need to do by leveraging the logic that already exists in the grid.

    -Matt