Popup on CurrentCellEditBegin

Does anyone know how to get the coordinates of a GridCell in a SfDataGrid? I want to have a popup appear with a styled TextBox when the user starts to edit the cell. I want the popup to appear above the cell (but probably bigger than the cell by itself). I have searched and I can't figure out a way to get the cell's location on the screen.

Thank you for any help you can provide!

3 Replies

SR Sivakumar R Syncfusion Team July 7, 2016 11:33 AM UTC

Hi Tim, 
 
Your requirement can be achieved by handling below three events. Find the code snippet and sample below, 
 
 
this.SfdataGrid.CurrentCellBeginEdit += SfdataGrid_CurrentCellBeginEdit; 
this.SfdataGrid.CurrentCellEndEdit += SfdataGrid_CurrentCellEndEdit; 
this.SfdataGrid.Loaded += SfdataGrid_Loaded; 
 
/// <summary> 
/// Open the PopUp and places based on cell's position 
/// </summary> 
/// <param name="sender"></param> 
/// <param name="args"></param> 
private void SfdataGrid_CurrentCellBeginEdit(object sender, CurrentCellBeginEditEventArgs args) 
{ 
    var rowline = this.SfdataGrid.GetVisualContainer().ScrollRows.GetVisibleLineAtLineIndex(args.RowColumnIndex.RowIndex); 
    var colline = this.SfdataGrid.GetVisualContainer().ScrollColumns.GetVisibleLineAtLineIndex(args.RowColumnIndex.ColumnIndex); 
 
 
    popUP.PlacementTarget = this.SfdataGrid.GetVisualContainer(); 
    popUP.Placement = PlacementMode.Relative; 
    popUP.HorizontalOffset = colline.ClippedOrigin; 
    popUP.VerticalOffset = rowline.ClippedOrigin; 
    popUP.IsOpen = true; 
} 
 
/// <summary> 
/// Closes the PopUp. 
/// </summary> 
/// <param name="sender"></param> 
/// <param name="args"></param> 
private void SfdataGrid_CurrentCellEndEdit(object sender, CurrentCellEndEditEventArgs args) 
{ 
    popUP.IsOpen = false; 
} 
 
private void SfdataGrid_Loaded(object sender, RoutedEventArgs e) 
{ 
    this.SfdataGrid.GetVisualContainer().ScrollOwner.ScrollChanged += ScrollOwner_ScrollChanged; 
} 
 
/// <summary> 
/// Update the PopUp position while scrolling. 
/// </summary> 
/// <param name="sender"></param> 
/// <param name="e"></param> 
private void ScrollOwner_ScrollChanged(object sender, ScrollChangedEventArgs e) 
{ 
    var currentcell = SfdataGrid.SelectionController.CurrentCellManager; 
 
    if (!currentcell.HasCurrentCell) 
    { 
        popUP.IsOpen = false; 
        return; 
    } 
 
    var rowline = this.SfdataGrid.GetVisualContainer().ScrollRows.GetVisibleLineAtLineIndex(currentcell.CurrentRowColumnIndex.RowIndex); 
    var colline = this.SfdataGrid.GetVisualContainer().ScrollColumns.GetVisibleLineAtLineIndex(currentcell.CurrentRowColumnIndex.ColumnIndex); 
 
    if (rowline == null || colline == null) 
    { 
        popUP.IsOpen = false; 
        return; 
    } 
 
    popUP.HorizontalOffset = colline.ClippedOrigin; 
    popUP.VerticalOffset = rowline.ClippedOrigin; 
    popUP.IsOpen = true; 
} 
 
 
 
Thanks, 
Sivakumar 



TS Tim Stephansen July 7, 2016 12:46 PM UTC

Dear Sivakumar,

Thank you for your assistance. It is greatly appreciated.

Best Regards,

Tim


JG Jai Ganesh S Syncfusion Team July 8, 2016 04:10 AM UTC

Hi Tim, 
 
Thank you for the update. 
 
Please let us know if you need further assistance on this. 
 
Regards, 
Jai Ganesh S 


Loader.
Up arrow icon