none
DataGridView Datenformat in einer Spalte RRS feed

  • Frage

  • Hallo Forum,

    ich habe in einem DataGridView ein Spalte in der ich Zahlen im Format   #.###.###,##   darstellen möchte.

    in der Darstellung "DeafultCellStyle" habe ich im CellStyle Generator die Form "Numerisch" mit 2 Dezimalstellen ( N2 ) ausgewählt.

    Leider kann ich in der Spalte eigeben was ich will auch Buchstaben die Formatvorgabe funktioniert nicht.

    Was mache ich falsch ?


    Gruß Roland
    Mittwoch, 1. Dezember 2010 14:15

Antworten

  • Hallo Roland,
    
    zum Beispiel:
    
     public partial class Form1 : Form
     {
      DataGridView dgv = new DataGridView();
      class Produkt
      {
       public string Name { get; set; }
       public int Wert { get; set; }
      }
      List<Produkt> produktListe = new List<Produkt>{
       new Produkt{Name="Produkt1", Wert=1234567},
       new Produkt{Name="Produkt2", Wert=12345678},
       new Produkt{Name="Produkt3", Wert=1234567890}};
    
      public Form1()
      {
       InitializeComponent();
       Controls.Add(dgv);
       dgv.Dock = DockStyle.Fill;
       dgv.DataSource = produktListe;
       dgv.Columns[1].DefaultCellStyle.Format = "#,#.00";
      }
     }
    

    Wenn Du es mit Währungs-Kennzeichen haben möchtest, könnte auch folgendes in Betracht kommen:

    dgv.Columns[1].DefaultCellStyle.Format = "c";
    

    ciao Frank
    Samstag, 4. Dezember 2010 14:50

Alle Antworten

  • Hallo Roland,
    
    zum Beispiel:
    
     public partial class Form1 : Form
     {
      DataGridView dgv = new DataGridView();
      class Produkt
      {
       public string Name { get; set; }
       public int Wert { get; set; }
      }
      List<Produkt> produktListe = new List<Produkt>{
       new Produkt{Name="Produkt1", Wert=1234567},
       new Produkt{Name="Produkt2", Wert=12345678},
       new Produkt{Name="Produkt3", Wert=1234567890}};
    
      public Form1()
      {
       InitializeComponent();
       Controls.Add(dgv);
       dgv.Dock = DockStyle.Fill;
       dgv.DataSource = produktListe;
       dgv.Columns[1].DefaultCellStyle.Format = "#,#.00";
      }
     }
    

    Wenn Du es mit Währungs-Kennzeichen haben möchtest, könnte auch folgendes in Betracht kommen:

    dgv.Columns[1].DefaultCellStyle.Format = "c";
    

    ciao Frank
    Samstag, 4. Dezember 2010 14:50
  • Hallo Frank,

    Danke für die Info.


    Gruß Roland
    Donnerstag, 9. Dezember 2010 13:03