Autor Beitrag
erfahrener Neuling
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 233
Erhaltene Danke: 19

Win 7, Win 10
C#, ASP-MVC (VS 2017 Community), MS SQL, Firebird SQL
BeitragVerfasst: Mo 02.05.16 11:32 
Hallo,

ich habe ein DataGridView, welches mit einer Tabelle befüllt wird (per DataSource).

Danach weise ich dem DataGridView erst Werte wie Spaltenname, Alignment usw. zu. Das funktioniert auch alles. Jetzt wollte ich aber noch Formate festlegen (zB Datum "d" oder Währung "c"), nur ändert sich nichts. Das gleiche Prinzip hat in einem anderen Programm aber auch schon funktioniert, also liegt es vielleicht an einer Eigenschaft des DataGridViews?

etwas Code:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
                                     //liefert Tabelle zurück
this.dataGridViewMaster.DataSource = this.dbConnect.ExecuteProcedure(this.procedureNames[1], parameters);
SetUpDataGridViews();

---------------------------------------------------------------------------------------------------------
private void SetUpDataGridViews() 
{
    this.dataGridViewMaster.Columns[0].Name = "BelegDatum";
    this.dataGridViewMaster.Columns[0].HeaderText = "Datum";
    this.dataGridViewMaster.Columns[0].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
    this.dataGridViewMaster.Columns[0].DefaultCellStyle.Format = "d";    //müsste ja das Date als Datum ohne 00:00:00 anzeigen

    this.dataGridViewMaster.Columns[1].Name = "Betrag";
    this.dataGridViewMaster.Columns[1].HeaderText = "Betrag";
    this.dataGridViewMaster.Columns[1].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
    this.dataGridViewMaster.Columns[1].DefaultCellStyle.Format = "c";    //müsste ja die Zahl als Währung mit Euro-Zeichen anzeigen
}

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
Gewünschter Output           Momentaner Output
|------------|---------|     |-----------------------|--------|
|   Datum    |  Betrag |     |         Datum         | Betrag |
|------------|---------|     |-----------------------|--------|
| 02.05.2016 |  5,23€  |     |  02.05.2016 00:00:00  |  5,23  |
|------------|---------|     |-----------------------|--------|

Jemand ne Idee?


Zuletzt bearbeitet von erfahrener Neuling am Mo 02.05.16 11:59, insgesamt 1-mal bearbeitet
Ralf Jansen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 4708
Erhaltene Danke: 991


VS2010 Pro, VS2012 Pro, VS2013 Pro, VS2015 Pro, Delphi 7 Pro
BeitragVerfasst: Mo 02.05.16 11:46 
Ist das der tatsächliche Code und der tatsächliche Output?
Die Spaltenreihenfolge passt nicht zusammen.
erfahrener Neuling Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 233
Erhaltene Danke: 19

Win 7, Win 10
C#, ASP-MVC (VS 2017 Community), MS SQL, Firebird SQL
BeitragVerfasst: Mo 02.05.16 11:58 
Oh stimmt, hatte den Code nur als Beispiel hingeschrieben. Hab's bearbeitet.
Ralf Jansen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 4708
Erhaltene Danke: 991


VS2010 Pro, VS2012 Pro, VS2013 Pro, VS2015 Pro, Delphi 7 Pro
BeitragVerfasst: Mo 02.05.16 12:08 
Was kommt denn aus der ExecuteProcedure Funktion zurück? Insbesondere welche Datentypen kommen da für Datum,Betrag zurück? Wenn das schon strings sind hilft formatieren nicht. Nur das formatieren von speziellen Datentypen nach string werden durch die Formatierung berücksichtigt (sonst bräuchte man ja auch 2 Formate einmal wie die Quelle formatiert ist und einmal wie man das Ziel formatiert haben möchte)

Für diesen Beitrag haben gedankt: erfahrener Neuling
erfahrener Neuling Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 233
Erhaltene Danke: 19

Win 7, Win 10
C#, ASP-MVC (VS 2017 Community), MS SQL, Firebird SQL
BeitragVerfasst: Mo 02.05.16 12:17 
Oh shit, dachte ich hätte das auschließen können. Ja Typen sind alle string, sollten es aber nicht. Ursache: in der Auslese-Schleife: reader.GetString(); :autsch:
Naja jetzt weiß ich, woran's liegt.