Click here to Skip to main content
15,867,594 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi All,

I would like to aks you, can someone tell me, how can I dynamically create multilayer headers DataGrid?

My data are changing so I cannot set those headers in xaml code.

All depends on DatePicker selections - I have Two DatePickers, and the code is:

VB
DataGrid1.DataContext = Nothing
DataGrid1.Columns.Clear()
'Controls.Add(DataGrid1)
DataGrid1.Visibility = Windows.Visibility.Visible
'DataGrid1.Update()
Dim startDate As DateTime = DateTimePicker1.SelectedDate
Dim endDate As DateTime = DateTimePicker2.SelectedDate
Dim numberOfDays As Integer = (endDate.Date - startDate.Date).Days + 1
For dayCount As Integer = 0 To (numberOfDays - 1)
    Dim currentDate As Date = Convert.ToDateTime(startDate.AddDays(dayCount))
    Dim formatedD As String = currentDate.ToString("dd")
    If currentDate.DayOfWeek <> DayOfWeek.Saturday AndAlso currentDate.DayOfWeek <> DayOfWeek.Sunday Then
        Dim c1 As New DataGridTextColumn
        c1.Header = formatedD
        DataGrid1.Columns.Add(c1)
    End If
Next dayCount


It works fine. App is creating day column. But, how to create additional header that would indicate name of the Month above the days related to this month. (days columns are in order from 1 to ...n)

What I would like to achieve (more or less view like this one)
http://www.newfazeindustries.com/picofboard.JPG[^][]

Thank you very much for any solution.

BR
Posted
Updated 14-Feb-14 8:52am
v4
Comments
Sergey Alexandrovich Kryukov 12-Feb-14 16:52pm    
It would be good if you show or describe exactly what do you want to achieve. You can simulate the view using HTML directly shown in your question text (use "Improve question").
In WPF, you really have enough flexibility to show complex content, but it all requires some search and learning.
—SA

1 solution

VB
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        DataGrid1.DataSource = Nothing
        DataGrid1.Columns.Clear()
        'Controls.Add(DataGrid1)
        'DataGrid1.Visible = True
        'DataGrid1.Update()
        Dim startDate As DateTime = DateTimePicker1.Value
        Dim endDate As DateTime = DateTimePicker2.Value
        Dim numberOfDays As Integer = (endDate.Date - startDate.Date).Days + 1
        For dayCount As Integer = 0 To (numberOfDays - 1)
            Dim currentDate As Date = Convert.ToDateTime(startDate.AddDays(dayCount))
            Dim formatedD As String = currentDate.ToString("dd")
            If currentDate.DayOfWeek <> DayOfWeek.Saturday AndAlso currentDate.DayOfWeek <> DayOfWeek.Sunday Then
                Dim c1 As New DataGridViewColumn
                c1.HeaderText = Format(currentDate, "MMM") & vbCrLf & formatedD
                DataGrid1.Columns.Add(c1)
            End If
        Next dayCount
    End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900