Skip to main content Skip to footer

Display Row Index in C1FlexGrid for LightSwitch

With this blog, we will be discussing on how to display the Row Index in C1FlexGrid for LightSwitch while maintaining the delete icon and new row icon in row header of C1FlexGrid. We cannot show delete icon and new row icon along with row index in same column. Hence, we will add a new column and show row indexes in that column. By doing this, the default functionality to show delete icon and add row icon will be maintained along with showing row indexes. This is how output will look like:- For this, first of all we need to add a column in row header of C1FlexGrid for LightSwitch. While doing this, we will override the CreateRowHeaderContent method of the default CellFactory class and will display row indexes in newly added column. The code snippet implements the same:-


void proxy_ControlAvailable(object sender, ControlAvailableEventArgs e)  
{  
    var fg = e.Control as C1FlexGrid;  
    fg.RowHeaders.Columns.Add(new Column());  
    if (fg != null)  
    {  
        Microsoft.LightSwitch.Threading.Dispatchers.Main.BeginInvoke(() =>  
        { fg.CellFactory = new RowHeaderCellFactory(fg); });  
    }  
}  
public class RowHeaderCellFactory : C1.LightSwitch.FlexGrid.Presentation.Controls.LSCellFactory  
{  
    public RowHeaderCellFactory(C1FlexGrid grid)  
        : base(grid)  
    {  

    }  
    public override void CreateRowHeaderContent(C1FlexGrid grid, Border bdr, CellRange range)  
    {  
        base.CreateRowHeaderContent(grid, bdr, range);  
        if (range.Column == 1)  
        {  
            dynamic tb = new TextBlock();  
            tb.HorizontalAlignment = HorizontalAlignment.Center;  
            tb.VerticalAlignment = VerticalAlignment.Center;  
            tb.Text = string.Format("{0}", range.Row + 1);  
            bdr.Padding = new Thickness(0);  
            bdr.Child = tb;  
        }  
    }  
}  

Like this, various other customizations can also be implemented. If you have some specific user requirements or customizations or suggestions regarding the same then let us know. We would be happy to cater them :)

MESCIUS inc.

comments powered by Disqus