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
570
Fixed Header Column
posted

Has anyone ever used a column as a "slider" (for lack of a better term) to set which columns are pinned (i.e using Fixed headers)? I would like to be able to add a column to the grid such that when the column is moved all columns to the left (and the column itself) will be pinned. The user should be able to drag the column by dragging the header or any portion of the column.

 I have played around with it and have gotten pretty close to the correct behavior, but not exact. The attached file shows what I am looking for (the "frozen" column is outlined in red). 

I have tried using the BeforeColPosChanged event w/o much luck... any advice would be greatly appreciated! 

 

Thanks,
Sean

Parents
  • 570
    posted

    As a follow up.... I was able to get this 99% percent the way I wanted, perhaps someone else can get the 1%?

    I ended up using a combination of two events:

     

     

    void dgOrders_MouseDown(object sender, MouseEventArgs e){

    UltraGrid grid = (UltraGrid)sender;

     

     

    UIElement element = grid.DisplayLayout.UIElement.LastElementEntered;

    Infragistics.Win.UltraWinGrid.

    ColumnHeader header = element.GetContext(typeof(Infragistics.Win.UltraWinGrid.ColumnHeader)) as Infragistics.Win.UltraWinGrid.ColumnHeader;

     

     

    if (header != null){

    if (header.Column.Key == "Frozen")

     

     

    foreach (UltraGridColumn ugc in dgOrders.DisplayLayout.Bands[0].Columns)

    if (ugc.Header.Fixed) ugc.Header.Fixed = false;}

    }

     

     

    void dgOrders_BeforeColPosChanged(object sender, BeforeColPosChangedEventArgs e)

    {Infragistics.Win.UltraWinGrid.ColumnHeader header = e.ColumnHeaders[0];

     

     

    int oldpos = dgOrders.DisplayLayout.Bands[0].Columns[e.ColumnHeaders[0].Column.Key].Header.VisiblePosition;

     

     

    int newpos = header.VisiblePosition;

     

     

    if (e.PosChanged == PosChanged.Moved && header.Column.Key == "Frozen"){

     

     

    if

    (newpos > oldpos)

    {

     

     

    foreach (UltraGridColumn ugc in dgOrders.DisplayLayout.Bands[0].Columns)

    ugc.Header.Fixed = ugc.Header.VisiblePosition <= newpos ?

    true : false;

    header.Fixed = 

    true; }

     

     

    else

    {

     

     

     

    foreach (UltraGridColumn ugc in dgOrders.DisplayLayout.Bands[0].Columns)

    ugc.Header.Fixed = ugc.Header.VisiblePosition < newpos ?

    true : false;

    header.Fixed = true;

    }

    }

    }

    The MouseDown event allows me to unpin all pinned column if the "freeze" column header is clicked. This seems to be necessary since if the "freeze" column is pinned, it cannot be moved to a new position. Hence, once it is pinned you can no longer use it to subsequently set the pinned columns.

    After that, the BeforeColPosChanged event can be caught and some simple logic can determine (based on the relationship b/w the new position and old position) which columns should be frozen in the new configuration.

    The only issue arises when the "frozen" column header is clicked but not moved, the MouseDown event fires and all pinned columns become unpinned.... This is not the end of the world, I could use the column header click as a pinned column "reset" if need be (since there really isn't any other way to turn fixed column headers "off" due to the fact that all of the fixed header indicators are being suppressed when the grid is initialized). Ideally, when one clicks the "Frozen" column header and doesn't move it, nothing should happen... unfortunately there aren't very many Header "Click/Drag" events.....

Reply Children
No Data