Datagrids: How to format boolean values?

Hi All,

I'm working with a Datagrid in which one of the columns is populated using a boolean value (bit in SQLSrv). Is there a way I can format this value to show a more user-friendly message . I would like to display 'Activate' for False and 'Deactivate' for True.

Thanks in advance,



Answer this question

Datagrids: How to format boolean values?

  • lipi

    Hi
    I find this solution. This work OK if field is read only. I hope this help you.

    private void activatesTableDataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
    {
    if (activatesTableDataGridView.Columns[e.ColumnIndex].Name.Equals("ActiveColumn"))
    {
    try
    {
    bool b;
    if (Boolean.TryParse(e.Value.ToString(), out b))
    {
    e.Value = (b "Active" : "Deactive");
    }
    }
    catch (Exception) { }
    }
    }

    Yours
    Markku

  • dagfari

    Can anyone help
  • loopool

    Anyone has any hints on this . I found some articles but the solutions they post are very complicated.
  • ChristianBG

    You can use views for that. You can use Sql server view or runtume DataView. At the end you can use sql statement to fill your table, but not taking data with select *, but with some column change.

  • NukeMan

    Hi;

    I have done something similar on one of my projects. I usually build my datatable and add a column with the IFF expression.

    IFF(booleabVal>0,'Activate','Deactivate')

    Shivam


  • Datagrids: How to format boolean values?