ASPxGridView with Column Icon Library
Autor: Willon Félix | Publicado: 2016-10-13T11:18:00-03:00

Neste post irei mostrar como montar uma lista com o controle&nbsp;ASPxGridView da DeveExpress. Nesse controle terá uma coluna que mostra a imagem que representa a extensão de um determinado tipo de arquivo.


.ASPX







.CS (C#):



Na classe que representa o objeto que será exibido no grid, modifique a propriedade Imagem_Extensao para que ela busque qual o nome da imagem a partir da sigla/extensão do arquivo.




public partial class Formato_Arquivo_Grid_BD

&nbsp; &nbsp; {

&nbsp; &nbsp; &nbsp; &nbsp; public short Codigo { get; set; }

&nbsp; &nbsp; &nbsp; &nbsp; public string Descricao { get; set; }

&nbsp; &nbsp; &nbsp; &nbsp; public string Sigla { get; set; }

&nbsp; &nbsp; &nbsp; &nbsp; public bool Exibir { get; set; }

&nbsp; &nbsp; &nbsp; &nbsp; public string Imagem_Extensao {



&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; get

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return Formato_Arquivo_NG.Pegar_Nome_Imagem(Sigla);

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }

&nbsp; &nbsp; &nbsp; &nbsp; }



&nbsp; &nbsp; }




Método que define o nome da imagem da biblioteca do DevExpress:




public static string Pegar_Nome_Imagem(string pSigla)

&nbsp; &nbsp; &nbsp; &nbsp; {

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string oNome = "default.gif";



&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; switch (pSigla)

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case "PDF":

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oNome = "export_exporttopdf_16x16";

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case "XLS":

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oNome = "export_exporttoxls_16x16";

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case "XLSX":

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oNome = "export_exporttoxlsx_16x16";

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case "RTF":

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oNome = "export_exporttortf_16x16";

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case "MHT":

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oNome = "export_exporttomht_16x16";

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case "HTML":

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oNome = "export_exporttohtml_16x16";

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case "TXT":

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oNome = "export_exporttotxt_16x16";

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case "CSV":

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oNome = "export_exporttocsv_16x16";

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case "Image":

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oNome = "export_exporttoimg_16x16";

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; default:

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }



&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return oNome;

&nbsp; &nbsp; &nbsp; &nbsp; }




Carregando o grid:




&nbsp;private void Carregar_Tela()

&nbsp; &nbsp; &nbsp; &nbsp; {

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; using (DB_Banco xBD = new DB_Banco())

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; grv_Formatos.DataSource = BO_Formato_Arquivo.Pesquisar_Grid(xBD, new Formato_Arquivo_BD());

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; grv_Formatos.DataBind();

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;



&nbsp; &nbsp; &nbsp; &nbsp; }