Home Forums WinForms controls Xceed Grid for WinForms How make synchronization of two grid,when sort one grid

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #16621 |

    Hello ,I have to make a report,but for some reasons,I must make to grid for this report ,when I sort one column of one grid ,the other grid must synchronization ,how i can do?

    many thanks

    Imported from legacy forums. Posted by Hot (had 958 views)

    User (Old forums)
    Member
    Post count: 23064

    Handle the SortDirectionChanged event on Column to manually synchronize the other grid.

    private void Form1_Load( object sender, EventArgs e )

    {

        foreach( Column col in gridControl1.Columns )

        {

            col.SortDirectionChanged +=

    new EventHandler( col_SortDirectionChanged );

        }

    }

    void col_SortDirectionChanged( object sender, EventArgs e )

    {

        Column col = sender as Column;

        if( col != null )

        {

            if( col.SortDirection == SortDirection.Ascending )

            {

                //Sort the other grid’s corresponding column in Ascending order

                //You can use the col.FieldName to identify the column.

            }

            else if( col.SortDirection == SortDirection.Descending )

            {

                //Sort the other grid’s corresponding column in Descending order

            }

        }

    }

     

    Imported from legacy forums. Posted by André (had 473 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks for your rpply,I know your method can handle the situation of two grid of same view and same data,but our request is one table separate into two part,and add each to two grid,ect ,there are some columns in  one table (col1,col2…col10),first grid (col1,col2…col6) second (col7…col10),when we sort col10,i want synchronize  first grid by sort of  column  col10.thank you very much.

    Imported from legacy forums. Posted by Hot (had 355 views)

    User (Old forums)
    Member
    Post count: 23064

    The only way I can think this would be possible is to have both grids have all the columns, but hide the columns you don’t want in each grid (e.g. in grid 1 hide col7…col10 and in grid 2 hide col1…col6).  Then do the sorting as in the code I supplied on the hidden columns, and the grids should synchronize properly.

    Imported from legacy forums. Posted by André (had 275 views)

    User (Old forums)
    Member
    Post count: 23064

    Many thanks I wil try it,but i have another question how can i make synchronization for scoll bars?

    Imported from legacy forums. Posted by Hot (had 369 views)

    User (Old forums)
    Member
    Post count: 23064

    You will need to find the first row being displayed at the top of one grid, and call BringIntoView() on the corresponding row in the other grid.

    Imported from legacy forums. Posted by André (had 1168 views)

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.