Skip to content

Infragistics Community Forum / Desktop / Ultimate UI for ASP.NET Web Forms / Convert grid cell display values ‘true/false’ into ‘Yes/No’

Convert grid cell display values ‘true/false’ into ‘Yes/No’

New Discussion
Brian
Brian asked on Dec 8, 2011 3:17 PM

I’d like to change what the user sees in the grid. Let’s say I have a boolean column that is showing ‘true’ or ‘false’ and I’d like to show ‘Yes’ or ‘No’ instead.

I seem to be able to accomplish this somewhat by placing some code in the InitializeRow event.

Like…

GridRecordItem activated = e.Row.Items.FindItemByKey(“Activated”);

if (activated != null)

{

if ((bool)activated.Value == false)

activated.Text = “No”;

if ((bool)activated.Value == true)

activated.Text = “Yes”;

}

 

This seems to work, however if I edit a different value in the row and move to another row the formatting on the ‘Yes/No’ reverts back to ‘true/false’.

So, it seems that after a row has been updated I need to reapply the formatting.

Where is the appropriate place to format the display value of a cell?

Thanks,

Brian.

Sign In to post a reply

Replies

  • 0
    Alex E
    Alex E answered on Dec 8, 2011 2:57 PM

    Hello Brian,

    Look at the following forum thread and let me know if this is the functionality that you require – http://community.infragistics.com/forums/p/57603/293756.aspx#293756

    • 0
      Brian
      Brian answered on Dec 8, 2011 3:17 PM

      Well, not exactly what I was looking for. However, I did stumble across a solution.

      Each column has a FormatFieldMethod. So, for the true/false to Yes/No conversion, you can define a conversion method like…

      private
      string FormatTrueFalseToYesNo(ControlDataField field, object
      value)

      {


      if (value is Boolean)


      {


      Boolean trueFalse = (Boolean)value;

       


      if (trueFalse == true)


      return "Yes";

       


      if (trueFalse == false)


      return "No";


      }


      return "Error";

      }

       

      Then in the Initialize row event I do…

      GridRecordItem activated = e.Row.Items.FindItemByKey("Activated");

      if
      (activated != null &&
      activated.Column.FormatFieldMethod == null)

      {


      activated.Column.FormatFieldMethod = new FormatRecordItemValue(FormatTrueFalseToYesNo);

      }

      Now all of the true / false fields say Yes or No and this stays updated when I edit other cells in a row and move to other rows.

      This is not a solution if you want to be able to type in Yes or No, this is only a solution to display a different text in a cell.

       

       

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Brian
Favorites
0
Replies
2
Created On
Dec 08, 2011
Last Post
14 years, 2 months ago

Suggested Discussions

Created by

Created on

Dec 8, 2011 3:17 PM

Last activity on

Feb 12, 2026 9:48 AM