Changing Data while binding

2 posts, 0 answers
  1. fgalarraga
    fgalarraga avatar
    18 posts
    Member since:
    May 2007

    Posted 08 Jul 2007 Link to this post

    Is there a way to change the data in a cell during the bind event?

    Example: Date column, if the column = "01/01/1900" then column data = ""

    How would you do this with the GridView Control?

    Thank you,
    Frank
  2. Phi
    Phi avatar
    19 posts
    Member since:
    Jun 2007

    Posted 08 Jul 2007 Link to this post

    Hi fgalarraga,

    The way I would do this is to subscribe to the CellFormatting event of the GridView. Within the handler, you can check if the cell value is a date, check if it is 01/01/1900, and reformat accordingly:

    this.radGridView1.CellFormatting += new Telerik.WinControls.UI.CellFormattingEventHandler(this.radGridView1_CellFormatting);  
     
    private void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)  
    {  
        if (e.CellElement.Value is DateTime)  
        {  
            DateTime cellDateValue = (DateTime) e.CellElement.Value;  
            if (cellDateValue == new DateTime(1900, 1, 1))  
                e.CellElement.Text = "";  
        }  

    Cheers
    Phi
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top