WPF datagrid column heading span more than once column

后端 未结 6 598
轮回少年
轮回少年 2020-12-30 17:14

In a WPF datagrid is it possible to group column headings?

What I\'m after is

| Column 1 | Column 2 | Column 3|
| a  b  c  | a  b  c  | a  b  c |
|          


        
6条回答
  •  孤独总比滥情好
    2020-12-30 17:37

    This is an old thread, but I thought I should share how I did it.

    In my application, I want to display three columns of date entries, under a single column header, "Maintenance Fee Dates." I created a single column, with two DataTemplates, one for display and one for editing:

    
      
         
            
               
               
               
            
            
            
            
         
      
      
         
            
               
               
               
            
            
            
            
         
      
    

    Then I define the column as a DataGridTemplateColumn, pointing at the DataTemplates above:

    
    ....
       
    ....
    
    

    Since the DataTemplate is laid out with a Grid that has three fixed-length columns, I get three nice columns of dates (or DatePickers when editing) under the single column header.

    Horizontal Gridlines can be handled by the Grid. To have vertical Gridlines between the three columns, just put the middle column's control in a Border control. Set the Border control to the same width as the Grid column, display only its right and left borders, and set its BorderBrush to match the color of the DataGrid's Gridlines:

      
         
            
               
               
               
            
            
            
               
                  
               
            
            
         
      
    

提交回复
热议问题