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 25.04.16 14:41 
Hallo,

ich befürchte, die Antwort bereits zu kennen, aber gibt es eine Möglichkeit, 1. die erste Spalte Centermäßig anzuordnen und 2. die Einträge dazu auch, ohne irgendwelche Draw-Methoden zu überschreiben (davon hab ich nämlich keine Ahnung)?

Das ganze soll etwa so aussehen:
Beispiel

Danke für Antworten, muss doch eigntl möglich sein, oder?
Einloggen, um Attachments anzusehen!
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4805
Erhaltene Danke: 1061

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Mo 25.04.16 15:36 
Hallo,

nein, ohne Selberzeichnen kann das ListView die erste Spalte nur linksbündig anzeigen.
Aber der Aufwand dafür ist recht gering:
- OwnerDraw = true
- Ereignis DrawSubItem abonnieren und den Text per DrawString (mit Alignment = StringAlignment.Center) zeichnen
- für den Header das Ereignis DrawColumnHeader nehmen
s. z.B. Make an owner-drawn ListView control that draws server status information in C#

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: Di 26.04.16 09:44 
Jo danke dafür!

Ist ja wirklich nicht sooo kompliziert.
Habe es jetzt ganz simpel gemacht:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
private void listView1_DrawColumnHeader(object sender,DrawListViewColumnHeaderEventArgs e)
{
    string title = "Beschreibung";
    
    StringFormat format = new StringFormat();
    format.Alignment = StringAlignment.Center;
    format.LineAlignment = StringAlignment.Center;

    e.Graphics.FillRectangle(Brushes.Brown, e.Bounds);
    e.Graphics.DrawString(title, e.Font, Brushes.Black, e.Bounds, format);
}


EDIT: Frage in neues Thema umverlagert www.entwickler-ecke....ewtopic.php?t=115413