0

I am working on attendance report. Here I am getting Headers Startdate to enddate between dates. my problem to create sub-columns under the headers. Below is the screenshot which I want to get data structure.

enter image description here

I want AM and PM under the startdate to enddate below is the code to get header dates.

Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
    Dim startDate As Date = CType(dtpStartDate.SelectedDate, DateTime)
    Dim endDate As Date = CType(dtpEndDate.SelectedDate, DateTime)
    While startDate <= endDate
        Dim newColumn As DataGridTextColumn = New DataGridTextColumn()

        newColumn.Header = startDate.ToShortDateString()
        dgTemplate.Columns.Add(newColumn)
        startDate = startDate.AddDays(1)
    End While
End Sub

please help me to get sub-columns as AM and PM along with dates. Below XAML

<DataGrid x:Name="dgTemplate"  Margin="261,0,0,0" >
 <DatePicker x:Name="Startdate" HorizontalAlignment="Left" Margin="42,133,0,0" VerticalAlignment="Top"/>
    <DatePicker x:Name="Enddate" HorizontalAlignment="Left" Margin="40,0,0,0" VerticalAlignment="Center"/>
   
    <Button x:Name="Button" Click="Button_Click" Content="Button" HorizontalAlignment="Left" Margin="35,325,0,0" VerticalAlignment="Top"/>
<Window x:Class="test106.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
   xmlns:local="clr-namespace:test106"
    
    mc:Ignorable="d"
    xmlns:mynamespace="clr-namespace:test106"
    Title="MainWindow" Height="450" Width="800">
  <DataGridTemplateColumn.CellTemplate>
      <DataTemplate DataType="{x:Type local:DataGridRowItem}">
        <DataGrid ItemsSource="{Binding Columns[0].TableData}"
                  local:DataGridHelper.IsSynchronizeSelectedRowEnabled="True"
                  local:DataGridHelper.SynchronizeGroupKey="A"
                  RowHeaderWidth="0"
                  BorderThickness="0" />
methushal
  • 1
  • 3
  • https://stackoverflow.com/a/71849571/3141792 – BionicCode Apr 12 '22 at 21:59
  • thaanks for reply I am working on it – methushal Apr 13 '22 at 02:48
  • As per above link which you provided is getting xaml error in DataType="{x:Type local:DataGridRowItem}"> solution2 I added the code above where I am getting error in xaml. The error is The name Datagridrowitem does not exit in the name space. Could you please suggest me... – methushal Apr 13 '22 at 08:13
  • You must define the xaml namespace alias `local` so that it points to your project's namespace that contains the `DataGridRowItem` class definition. – BionicCode Apr 13 '22 at 08:28
  • I am not able to fix the error have a look once to fix this – methushal Apr 14 '22 at 04:12
  • Note that you have created two aliases for the same namespace: `mynamespace` and `local`. What exactly is not working, still the types are not found? Have tried to Clean and Rebuild your solution? Also can you check that the namespace is correct? Can you check that all files don't contain errors that prevent them from being compiled? – BionicCode Apr 14 '22 at 09:31
  • Thanks for your reply I will work on it – methushal Apr 14 '22 at 09:57

0 Answers0