How can I see a specific object's attribute on a DataGridView's cell?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















I want to be as clear as possible with this:



I have this class called "Tipo de Gasto"



public class CTipoGasto
{
public static List<CTipoGasto> listaTipoGasto = new List<CTipoGasto>();
public string descripción { get; set; }
public int ID { get; set; }

}


And as it is shown below, this object is an attribute of another object called "Gasto"



public class CGasto
{
public static List<CGasto> listaGasto = new List<CGasto>();
public string descripcion { get; set; }
public int ID { get; set; }
public CTipoGasto tipoDeGasto { get; set; } //here
public DateTime fecha { get; set; }
public double precio { get; set; }
}


Each one of those two lists are Data Sources of two different "Data Grid View", but the Gasto's attribute public CTipoGasto tipoDeGasto { get; set; } is shown like this on Gasto's DGV:
Click here to see the image



So I wanted to know how do I have to do to show TipodeGasto's attribute "Descripción"










share|improve this question































    1















    I want to be as clear as possible with this:



    I have this class called "Tipo de Gasto"



    public class CTipoGasto
    {
    public static List<CTipoGasto> listaTipoGasto = new List<CTipoGasto>();
    public string descripción { get; set; }
    public int ID { get; set; }

    }


    And as it is shown below, this object is an attribute of another object called "Gasto"



    public class CGasto
    {
    public static List<CGasto> listaGasto = new List<CGasto>();
    public string descripcion { get; set; }
    public int ID { get; set; }
    public CTipoGasto tipoDeGasto { get; set; } //here
    public DateTime fecha { get; set; }
    public double precio { get; set; }
    }


    Each one of those two lists are Data Sources of two different "Data Grid View", but the Gasto's attribute public CTipoGasto tipoDeGasto { get; set; } is shown like this on Gasto's DGV:
    Click here to see the image



    So I wanted to know how do I have to do to show TipodeGasto's attribute "Descripción"










    share|improve this question



























      1












      1








      1








      I want to be as clear as possible with this:



      I have this class called "Tipo de Gasto"



      public class CTipoGasto
      {
      public static List<CTipoGasto> listaTipoGasto = new List<CTipoGasto>();
      public string descripción { get; set; }
      public int ID { get; set; }

      }


      And as it is shown below, this object is an attribute of another object called "Gasto"



      public class CGasto
      {
      public static List<CGasto> listaGasto = new List<CGasto>();
      public string descripcion { get; set; }
      public int ID { get; set; }
      public CTipoGasto tipoDeGasto { get; set; } //here
      public DateTime fecha { get; set; }
      public double precio { get; set; }
      }


      Each one of those two lists are Data Sources of two different "Data Grid View", but the Gasto's attribute public CTipoGasto tipoDeGasto { get; set; } is shown like this on Gasto's DGV:
      Click here to see the image



      So I wanted to know how do I have to do to show TipodeGasto's attribute "Descripción"










      share|improve this question
















      I want to be as clear as possible with this:



      I have this class called "Tipo de Gasto"



      public class CTipoGasto
      {
      public static List<CTipoGasto> listaTipoGasto = new List<CTipoGasto>();
      public string descripción { get; set; }
      public int ID { get; set; }

      }


      And as it is shown below, this object is an attribute of another object called "Gasto"



      public class CGasto
      {
      public static List<CGasto> listaGasto = new List<CGasto>();
      public string descripcion { get; set; }
      public int ID { get; set; }
      public CTipoGasto tipoDeGasto { get; set; } //here
      public DateTime fecha { get; set; }
      public double precio { get; set; }
      }


      Each one of those two lists are Data Sources of two different "Data Grid View", but the Gasto's attribute public CTipoGasto tipoDeGasto { get; set; } is shown like this on Gasto's DGV:
      Click here to see the image



      So I wanted to know how do I have to do to show TipodeGasto's attribute "Descripción"







      c# winforms






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 16 '18 at 16:09









      LarsTech

      70.6k12109161




      70.6k12109161










      asked Nov 16 '18 at 15:49







      user9779039































          1 Answer
          1






          active

          oldest

          votes


















          0














          Override the ToString function of your class:



          public class CTipoGasto
          {
          public static List<CTipoGasto> listaTipoGasto = new List<CTipoGasto>();
          public string descripción { get; set; }
          public int ID { get; set; }

          public override string ToString() {
          return descripción;
          }
          }





          share|improve this answer
























          • Oh thanks! But.. is the "ID" Attribute hidden or something after that?

            – user9779039
            Nov 17 '18 at 6:39











          • @juanzitelli To combine two properties, try return ID.ToString() + ' ' + descripción;

            – LarsTech
            Nov 18 '18 at 21:09











          • That sounds great, but what I actually meant was: How can I show "TipoGasto" 's ID Property as another column in the datagridview just as with "descripción"

            – user9779039
            Nov 21 '18 at 5:00











          • @juanzitelli Depends. How are you filling the DataGridView? Using the DataSource? Or adding rows manually?

            – LarsTech
            Nov 21 '18 at 14:47











          • Data Source! dgvGrillaGasto.DataSource = null; dgvGrillaGasto.DataSource = CGasto.listaGasto; List<CGasto> listaFiltrada2 = new List<CGasto>(); if (txtBuscar.Text.Length > 0) { listaFiltrada2 = listaFiltrada2.FindAll(x => x.descripcion.ToUpper().Contains(txtBuscar.Text.ToUpper())); } dgvGrillaGasto.DataSource = listaFiltrada2;

            – user9779039
            Nov 21 '18 at 17:56














          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53341230%2fhow-can-i-see-a-specific-objects-attribute-on-a-datagridviews-cell%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown
























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Override the ToString function of your class:



          public class CTipoGasto
          {
          public static List<CTipoGasto> listaTipoGasto = new List<CTipoGasto>();
          public string descripción { get; set; }
          public int ID { get; set; }

          public override string ToString() {
          return descripción;
          }
          }





          share|improve this answer
























          • Oh thanks! But.. is the "ID" Attribute hidden or something after that?

            – user9779039
            Nov 17 '18 at 6:39











          • @juanzitelli To combine two properties, try return ID.ToString() + ' ' + descripción;

            – LarsTech
            Nov 18 '18 at 21:09











          • That sounds great, but what I actually meant was: How can I show "TipoGasto" 's ID Property as another column in the datagridview just as with "descripción"

            – user9779039
            Nov 21 '18 at 5:00











          • @juanzitelli Depends. How are you filling the DataGridView? Using the DataSource? Or adding rows manually?

            – LarsTech
            Nov 21 '18 at 14:47











          • Data Source! dgvGrillaGasto.DataSource = null; dgvGrillaGasto.DataSource = CGasto.listaGasto; List<CGasto> listaFiltrada2 = new List<CGasto>(); if (txtBuscar.Text.Length > 0) { listaFiltrada2 = listaFiltrada2.FindAll(x => x.descripcion.ToUpper().Contains(txtBuscar.Text.ToUpper())); } dgvGrillaGasto.DataSource = listaFiltrada2;

            – user9779039
            Nov 21 '18 at 17:56


















          0














          Override the ToString function of your class:



          public class CTipoGasto
          {
          public static List<CTipoGasto> listaTipoGasto = new List<CTipoGasto>();
          public string descripción { get; set; }
          public int ID { get; set; }

          public override string ToString() {
          return descripción;
          }
          }





          share|improve this answer
























          • Oh thanks! But.. is the "ID" Attribute hidden or something after that?

            – user9779039
            Nov 17 '18 at 6:39











          • @juanzitelli To combine two properties, try return ID.ToString() + ' ' + descripción;

            – LarsTech
            Nov 18 '18 at 21:09











          • That sounds great, but what I actually meant was: How can I show "TipoGasto" 's ID Property as another column in the datagridview just as with "descripción"

            – user9779039
            Nov 21 '18 at 5:00











          • @juanzitelli Depends. How are you filling the DataGridView? Using the DataSource? Or adding rows manually?

            – LarsTech
            Nov 21 '18 at 14:47











          • Data Source! dgvGrillaGasto.DataSource = null; dgvGrillaGasto.DataSource = CGasto.listaGasto; List<CGasto> listaFiltrada2 = new List<CGasto>(); if (txtBuscar.Text.Length > 0) { listaFiltrada2 = listaFiltrada2.FindAll(x => x.descripcion.ToUpper().Contains(txtBuscar.Text.ToUpper())); } dgvGrillaGasto.DataSource = listaFiltrada2;

            – user9779039
            Nov 21 '18 at 17:56
















          0












          0








          0







          Override the ToString function of your class:



          public class CTipoGasto
          {
          public static List<CTipoGasto> listaTipoGasto = new List<CTipoGasto>();
          public string descripción { get; set; }
          public int ID { get; set; }

          public override string ToString() {
          return descripción;
          }
          }





          share|improve this answer













          Override the ToString function of your class:



          public class CTipoGasto
          {
          public static List<CTipoGasto> listaTipoGasto = new List<CTipoGasto>();
          public string descripción { get; set; }
          public int ID { get; set; }

          public override string ToString() {
          return descripción;
          }
          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 16 '18 at 16:09









          LarsTechLarsTech

          70.6k12109161




          70.6k12109161













          • Oh thanks! But.. is the "ID" Attribute hidden or something after that?

            – user9779039
            Nov 17 '18 at 6:39











          • @juanzitelli To combine two properties, try return ID.ToString() + ' ' + descripción;

            – LarsTech
            Nov 18 '18 at 21:09











          • That sounds great, but what I actually meant was: How can I show "TipoGasto" 's ID Property as another column in the datagridview just as with "descripción"

            – user9779039
            Nov 21 '18 at 5:00











          • @juanzitelli Depends. How are you filling the DataGridView? Using the DataSource? Or adding rows manually?

            – LarsTech
            Nov 21 '18 at 14:47











          • Data Source! dgvGrillaGasto.DataSource = null; dgvGrillaGasto.DataSource = CGasto.listaGasto; List<CGasto> listaFiltrada2 = new List<CGasto>(); if (txtBuscar.Text.Length > 0) { listaFiltrada2 = listaFiltrada2.FindAll(x => x.descripcion.ToUpper().Contains(txtBuscar.Text.ToUpper())); } dgvGrillaGasto.DataSource = listaFiltrada2;

            – user9779039
            Nov 21 '18 at 17:56





















          • Oh thanks! But.. is the "ID" Attribute hidden or something after that?

            – user9779039
            Nov 17 '18 at 6:39











          • @juanzitelli To combine two properties, try return ID.ToString() + ' ' + descripción;

            – LarsTech
            Nov 18 '18 at 21:09











          • That sounds great, but what I actually meant was: How can I show "TipoGasto" 's ID Property as another column in the datagridview just as with "descripción"

            – user9779039
            Nov 21 '18 at 5:00











          • @juanzitelli Depends. How are you filling the DataGridView? Using the DataSource? Or adding rows manually?

            – LarsTech
            Nov 21 '18 at 14:47











          • Data Source! dgvGrillaGasto.DataSource = null; dgvGrillaGasto.DataSource = CGasto.listaGasto; List<CGasto> listaFiltrada2 = new List<CGasto>(); if (txtBuscar.Text.Length > 0) { listaFiltrada2 = listaFiltrada2.FindAll(x => x.descripcion.ToUpper().Contains(txtBuscar.Text.ToUpper())); } dgvGrillaGasto.DataSource = listaFiltrada2;

            – user9779039
            Nov 21 '18 at 17:56



















          Oh thanks! But.. is the "ID" Attribute hidden or something after that?

          – user9779039
          Nov 17 '18 at 6:39





          Oh thanks! But.. is the "ID" Attribute hidden or something after that?

          – user9779039
          Nov 17 '18 at 6:39













          @juanzitelli To combine two properties, try return ID.ToString() + ' ' + descripción;

          – LarsTech
          Nov 18 '18 at 21:09





          @juanzitelli To combine two properties, try return ID.ToString() + ' ' + descripción;

          – LarsTech
          Nov 18 '18 at 21:09













          That sounds great, but what I actually meant was: How can I show "TipoGasto" 's ID Property as another column in the datagridview just as with "descripción"

          – user9779039
          Nov 21 '18 at 5:00





          That sounds great, but what I actually meant was: How can I show "TipoGasto" 's ID Property as another column in the datagridview just as with "descripción"

          – user9779039
          Nov 21 '18 at 5:00













          @juanzitelli Depends. How are you filling the DataGridView? Using the DataSource? Or adding rows manually?

          – LarsTech
          Nov 21 '18 at 14:47





          @juanzitelli Depends. How are you filling the DataGridView? Using the DataSource? Or adding rows manually?

          – LarsTech
          Nov 21 '18 at 14:47













          Data Source! dgvGrillaGasto.DataSource = null; dgvGrillaGasto.DataSource = CGasto.listaGasto; List<CGasto> listaFiltrada2 = new List<CGasto>(); if (txtBuscar.Text.Length > 0) { listaFiltrada2 = listaFiltrada2.FindAll(x => x.descripcion.ToUpper().Contains(txtBuscar.Text.ToUpper())); } dgvGrillaGasto.DataSource = listaFiltrada2;

          – user9779039
          Nov 21 '18 at 17:56







          Data Source! dgvGrillaGasto.DataSource = null; dgvGrillaGasto.DataSource = CGasto.listaGasto; List<CGasto> listaFiltrada2 = new List<CGasto>(); if (txtBuscar.Text.Length > 0) { listaFiltrada2 = listaFiltrada2.FindAll(x => x.descripcion.ToUpper().Contains(txtBuscar.Text.ToUpper())); } dgvGrillaGasto.DataSource = listaFiltrada2;

          – user9779039
          Nov 21 '18 at 17:56






















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53341230%2fhow-can-i-see-a-specific-objects-attribute-on-a-datagridviews-cell%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Xamarin.iOS Cant Deploy on Iphone

          Glorious Revolution

          Dulmage-Mendelsohn matrix decomposition in Python