Click here to Skip to main content
15,884,810 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
I have a DataGrid with one DateTime column. i want this column to show Date time . for this I am using DatePicker.bot during run time the Datepicker gives a POP UP Calendar . but the calender is not responding to user click. what I have to do

Thanks in advance

HTML
<Style TargetType="Calendar" x:Key="CalenderStyleNew">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Calendar">
                    <StackPanel HorizontalAlignment="Center" x:Name="Root">
                        <Calendar x:Name="Calendar" SelectedDate="{TemplateBinding SelectedDate}"
                removed="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}"
                  BorderThickness="{TemplateBinding BorderThickness}" >
                            <Calendar.CalendarDayButtonStyle>
                                <Style>
                                    <Setter Property="Button.Height" Value="50"></Setter>
                                    <Setter Property="Button.Width" Value="50"></Setter>
                                    <Setter Property="Button.FontSize" Value="20"></Setter>
                                </Style>
                            </Calendar.CalendarDayButtonStyle>
                            <Calendar.CalendarButtonStyle>
                                <Style>
                                    <Setter Property="Button.Height" Value="50">
                                    </Setter>
                                    <Setter Property="Button.Width" Value="50">
                                    </Setter>
                                    <Setter Property="Button.FontSize" Value="20">
                                    </Setter>
                                </Style>
                            </Calendar.CalendarButtonStyle>
                        </Calendar>
                    </StackPanel>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
<DataTemplate x:Key="DateTemplate" >
        <StackPanel Width="100" Height="20" Orientation="Horizontal" >
            <Border removed="Black" BorderBrush="Black" BorderThickness="1">
                <TextBlock Width="20" Text="{Binding DOB, StringFormat={}{0:dd}}" FontSize="14" FontWeight="Bold" HorizontalAlignment="Center" Foreground="White" removed="Black" />
            </Border>
            <Border removed="Bisque" BorderBrush="Black" BorderThickness="1">
                <TextBlock Width="30" Text="{Binding DOB, StringFormat={}{0:MMM}}" FontSize="14" HorizontalAlignment="Center" Foreground="Red" removed="Bisque"/>                
            </Border>

            <Border removed="Green" BorderBrush="Black" BorderThickness="1">
                <TextBlock Width="50" Text="{Binding DOB, StringFormat={}{0:yyyy}}" FontSize="14" HorizontalAlignment="Center" Foreground="Red" removed="Green"/>
            </Border>

        </StackPanel>
    </DataTemplate>
    
    <!--working code-->    
    <DataTemplate x:Key="EditingDateTemplate">
        <DatePicker SelectedDate="{Binding DOB}" CalendarStyle="{DynamicResource CalenderStyleNew }"  />
       
    </DataTemplate>




 <dg:DataGrid.Columns>
                
                <dg:DataGridTextColumn ElementStyle="{StaticResource MyStyle}" EditingElementStyle="{StaticResource WrapStyle}" Header="Author ID" Binding="{Binding Path=AuthorID}"  />

                <dg:DataGridTemplateColumn Header="DOB" CellTemplate="{DynamicResource DateTemplate}" CellEditingTemplate="{DynamicResource EditingDateTemplate}"  />

            </dg:DataGrid.Columns>
Posted
Updated 2-Feb-12 9:20am
v2
Comments
Chris Maunder 2-Feb-12 15:26pm    
Please SA - not everyone has English as their first language, nor are we, as developers, renowned for our spelling. Vote, report, or even better, use your abililty to edit posts to correct it so that others can read it more easily. Making someone feel bad helps no one.
Keith Barrow 2-Feb-12 17:29pm    
It isn't pre-primary grammar. This is a perfectly reasonable question, I only wish I could help! I can suggest that you check the DOB property raises the PropertyChanged event (and its container class implements INotifyPropertyChanged), otherwise the UI won't know how to update. If you could supply us with the class that you bind to, that would be helpful.
[no name] 2-Feb-12 21:08pm    
DOB is a column in the DataBase.the code behind is ,

public MainWindow()
{
InitializeComponent();

connectionstring = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:/Project/Book.accdb";
connection = new OleDbConnection(connectionstring);
sql = "Select*from Authors";


dataGrid1.ColumnHeaderHeight = 50;

try
{
connection.Open();
oledbAdapter = new OleDbDataAdapter(sql, connection);
oledbAdapter.Fill(dt);
//dataGrid1.DataContext = dt;



dataGrid1.ItemsSource = dt.DefaultView;


}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}






} I think it can help somebody to probe the issue

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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