Change data in DataGrid

2

I'm working with C # in WPF, I'm using the data from an api, I have a datagrid that I filled with user data such as name, email, phone, status but in state it gives me 1 if it is active and 0 if it is deactivated , what I need in the table to show me the word Active if it is 1 and Deactivated if it is 0.

so I filled the datagrid

public void ListadoUsuarios()
    {
        List<UsuarioDTO> usuarios = new List<UsuarioDTO>();
        usuarios = GlobalVars.Client.GetAllUsuarios();
        gv_usuarios.ItemsSource = usuarios;
    }

Thanks !!

    
asked by Andrés Linares Avello 01.11.2018 в 22:15
source

1 answer

1

You can add a property to the class UsuarioDTO that returns this text that you need to show, then bindeas is to the grid column:

public class UsuarioDTO{

    //resto propiedades

    public string EstadoDesc
    {
      get { return this.Estado == 0 ? "Desactivado" : "Activo"; }
    }
}

That property readonly is the one you would link to the DataGrid column to display the text corresponding to the state.

    
answered by 01.11.2018 / 22:29
source