DataGrid template Elements events do not get fired
Last post 05-09-2008 8:26 AM by joer00. 2 replies.
Sort Posts:
05-07-2008 9:10 AM
DataGrid template Elements events do not get fired

This just drove me crazy as events SOMETIMES get fired and I could not figure out any rule on this ! I have a grid with many columns, placing GotFocus or LeftMouseButtonDown works ALWAYS on the first and second cell, but not on any other cell. Clicking FIRST on the first cell fires correctly begin cell edit events and than also for all others. Clicking first on ANY OTHER cell does not fire any event UNTIL one double clicks, than events get fired again on any other cell.

Totally confusing !

Template example

 

                <my:DataGridTemplateColumn Width="22">
                    <my:DataGridTemplateColumn.Header>
                        <TextBlock Style="{StaticResource DataGridHeader}" Text="Occ-"/>
                    </my:DataGridTemplateColumn.Header>
                    <my:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock NO EVENT HANDLERE HERE GETS FIRED IF NOT THE FIRST COLUMN x:Name="Column2" Text="{Binding MinPersons,Mode=OneWay}"  Style="{StaticResource DataText}" />
                        </DataTemplate>
                    </my:DataGridTemplateColumn.CellTemplate>
                    <my:DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <TextBox x:Name="tbColumn2" Text="{Binding MinPersons, Mode=TwoWay}" Style="{StaticResource IntegerTextBox2Digits}"
                                     TextChanged="TextBox_TextChanged"
                                     TabNavigation="Cycle"/>
                         </DataTemplate>
                    </my:DataGridTemplateColumn.CellEditingTemplate>
                </my:DataGridTemplateColumn>

Joe Robe

joer00

Joined on 07-05-2006
Posts 72
05-09-2008 3:19 AM
Re: DataGrid template Elements events do not get fired

Hello, can you post some code? I can't reproduce this issue. One thing to check is your TextBlock doesn't stretch the cell, so the MouseLeftButtonDown event (if you're handling it) will only fire when you click on the text. Try to give it an explicit Width.

shanaolanxing - Please mark the posts as answers if they help and unmark if they don't.

Yi-Lun Luo - MSFT

Joined on 10-29-2007
Posts 1,084
05-09-2008 8:26 AM
Re: DataGrid template Elements events do not get fired

 Yi,

thanks for you answer also to my other questions. You asked for demo code, unfortunately I am to busy to create special test projects as the issues happen during my real development. Can you contact me a NoSpam@robesoft.com with an email I can send you the whole project ?  

Joe Robe

joer00

Joined on 07-05-2006
Posts 72