Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

Datagrid not rendering a row. RSS

4 replies

Last post Aug 31, 2009 02:02 PM by cwpecora

(0)
  • cwpecora

    cwpecora

    Member

    1 Points

    8 Posts

    Datagrid not rendering a row.

    Aug 26, 2009 03:23 PM | LINK

     What is happening is I have a datagrid using DataGridTemplateColumn that consist of several hyperlinkbuttons, if you click on one everything works fine, new site opens in a new window and all is good until you return to the datagrid and run a new search for new data.  the Datagrid will refresh with the new search result however the row in which you previously click on a hyperlink is empty. By that i mean the row that should be there is blank, the correct amount of space is taken but no data is rendered.   From debugging i see the data for the row is there in the ItemsSource list.  After more digging it appears that the editingTemplateData private member has been set and I suspect that is what is keeping the row from rendering.  I do not see any way to cancel this edit or even comit the edit.  is there some way to get the datagrid out of editmode for templates?

     Any ideas on how to get around this issue?  I find no way to cancel the edit or even commit it and move on from the code side.  however, a work around i have found is to select another row (without clicking any of the templates controls) and then running a search to refresh the datagrid.  what am i missing?


    <!-- List View DataGrid -->
                        <StackPanel x:Name="spListView" >
                            <data:DataGrid  x:Name="dgSearchResults"
                                    CanUserSortColumns="True"
                                    Background="White"
                                    AlternatingRowBackground="LightGray"        
                                    Height="510"
                                    Visibility="Visible"
                                    AutoGenerateColumns="False" 
                                    SelectionMode="Single"
                                    SelectedIndex="0"     
                                    SelectionChanged="SearchResults_SelectionChanged"
                                    GridLinesVisibility="None"
                                    HorizontalGridLinesBrush="white"
                                    VerticalGridLinesBrush="white"
                                    HorizontalAlignment="Stretch"
                                    IsReadOnly="True"   >
                                <data:DataGrid.Columns>
                                    <data:DataGridTemplateColumn   
                                            Header="Map"       
                                            Width="40"  
                                            CellTemplate="{StaticResource dtMapView}"     
                                            CanUserSort="True"
                                            SortMemberPath="Index"
                                            CanUserResize="False"
                                            CanUserReorder="False"/>

                                    <data:DataGridTemplateColumn   
                                            Header="Profile"
                                            CellTemplate="{StaticResource dtMiniProfile}"              
                                            CanUserSort="True"
                                            SortMemberPath="Index"
                                            CanUserResize="False"
                                            CanUserReorder="False" 
                                            IsReadOnly="True"/> <!-- Width="680" -->
                                </data:DataGrid.Columns>
                            </data:DataGrid>
                        </StackPanel>

    <UserControl.Resources>

             <DataTemplate x:Key="dtMapView" >
                <Border BorderBrush="White" BorderThickness="1" Background="Transparent">
                    <Canvas Background="Transparent" Width="21" Height="29" >
                        <Image      x:Name="imMapIcon"   Source="{Binding Path=MapIcon}" Stretch="Fill"   
                                    Canvas.Left="0" Canvas.Top="0" Width="21" Height="29"  />
                        <StackPanel Width="21" Height="29" Canvas.Left="0" Canvas.Top="0" Canvas.ZIndex="1">
                            <TextBlock  x:Name="txMapIndex"  Text="{Binding Path=Index}" Foreground="White"
                                        FontWeight="Bold" FontFamily="Tahoma" VerticalAlignment="Center"
                                        HorizontalAlignment="Center" />
                        </StackPanel>
                    </Canvas>
                </Border>
            </DataTemplate>

            <DataTemplate x:Key="dtMiniProfile"  >
                <Border BorderBrush="White" BorderThickness="1" Background="Transparent">
                    <Grid Margin="0" >
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"  />
                        <ColumnDefinition Width="2.78*" MinWidth="142"  /> <!-- 161/51 = 3.16* -->
                        <ColumnDefinition Width="2.78*" MinWidth="142" /> <!-- 123/51 = 2.40* -->
                        <ColumnDefinition Width="1.76*" MinWidth="60"  /> <!--  60/51 = 1.78* -->
                        <ColumnDefinition Width="1.56*" MinWidth="80"  /> <!--  80/51 = 1.58* -->
                        <ColumnDefinition Width="1.86*" MinWidth="96"  /> <!--  96/51 = 1.88* -->
                        <ColumnDefinition Width="1.90*" MinWidth="100" /> <!--  72/51 = 1.41* -->
                    </Grid.ColumnDefinitions>
                    <Image  Grid.Column="0" Height="68" Width="51"
                            Source="{Binding Path=Image}" Stretch="Fill"   Margin="5,2,5,2"
                            ImageFailed="Image_ImageFailed"
                            MouseLeftButtonDown="AgentImage_Click" Cursor="Hand" />
                   
                    <StackPanel Orientation="Vertical" Grid.Column="1" Margin="10,5,5,5"  >
                        <HyperlinkButton    Content="{Binding Path=FormattedName}"
                        Click="HyperlinkButton_Click" Foreground="DarkBlue" FontWeight="Bold"/>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding Path=City}"            />
                            <TextBlock Text=", " />
                            <TextBlock Text="{Binding Path=State}"           />
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="Office: " />
                            <TextBlock Text="{Binding Path=Phone1}" />
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="Mobile: " />
                            <TextBlock Text="{Binding Path=Phone2}" />
                        </StackPanel>
                        <HyperlinkButton    Content="{Binding Path=Email1}"       
                        Click="MiniProfile_Email_Click" Foreground="DarkBlue"    ClickMode="Press"/>
                    </StackPanel>
                   
                    <StackPanel Orientation="Vertical" Grid.Column="2" Margin="10,5,5,0" >
                        <TextBlock     Text="{Binding Path=Company}"  FontWeight="Bold" />
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="Distance: "                    />
                            <TextBlock Text="{Binding Path=Miles}" />
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="Certification: "  />
                            <TextBlock Text="{Binding Converter={StaticResource FormatBoolString}, Path=IsCertified}" />
                        </StackPanel>
                    </StackPanel>
                   
                    <StackPanel Orientation="Vertical" Grid.Column="3"  VerticalAlignment="Center" Margin="2" >
                        <Image      x:Name="imFavIcon"   Source="{Binding Path=FavIcon}"
                                    Stretch="UniformToFill" Width="26" Height="26" Cursor="Hand" 
                                    MouseLeftButtonUp="FavoriteImage_MouseUp" HorizontalAlignment="Center"
                                    ToolTipService.ToolTip="Click the Star to make this Agent a Favorite." />
                            <HyperlinkButton    HorizontalAlignment="Center" Foreground="DarkBlue"
                                    Click="hlbFavorite_Click" ClickMode="Press"
                                    ToolTipService.ToolTip="Click the Star to make this Agent a Favorite." >
                                <HyperlinkButton.Content>
                                    <StackPanel Orientation="Vertical" HorizontalAlignment="Stretch">
                                        <TextBlock Text="Make me" TextWrapping="Wrap" HorizontalAlignment="Center" />
                                        <TextBlock Text="a Favorite" TextWrapping="Wrap" HorizontalAlignment="Center" />
                                    </StackPanel>
                                </HyperlinkButton.Content>                     
                            </HyperlinkButton>
                        </StackPanel>
                   
                    <StackPanel Orientation="Vertical" Grid.Column="4" VerticalAlignment="Center" Margin="2">
                        <Image Source="web_03.png" Width="30" Height="30" Stretch="None"
                                MouseLeftButtonUp="WebSite_MouseUP" Cursor="Hand" />
                        <HyperlinkButton Content="My Website" NavigateUri="{Binding Path=Website}" TargetName="_blank"                                             

                             Foreground="DarkBlue" HorizontalAlignment="Center" ClickMode="Press"/>
                    </StackPanel>
                   
                    <StackPanel Orientation="Vertical" Grid.Column="5" VerticalAlignment="Center" Margin="2">
                        <Image Source="community_05.png" Width="30" Height="30" Stretch="None"
                                MouseLeftButtonUp="Community_MouseUP" Cursor="Hand" />
                        <HyperlinkButton Content="My Community" NavigateUri="http://www.reoguru.com"
                                Foreground="DarkBlue" HorizontalAlignment="Center" TargetName="_blank" ClickMode="Press"/>
                    </StackPanel>
                   
                    <StackPanel Orientation="Vertical" Grid.Column="6" VerticalAlignment="Center" Margin="2">
                        <Image Source="pdf_07.png" Width="30" Height="30" Stretch="None"
                                MouseLeftButtonUp="Resume_MouseUp" Cursor="Hand" />
                            <HyperlinkButton Click="MiniProfile_PDF_Click" Foreground="DarkBlue"
                                    HorizontalAlignment="Center" ClickMode="Press">
                                <HyperlinkButton.Content>
                                    <StackPanel Orientation="Vertical" HorizontalAlignment="Stretch">
                                        <TextBlock Text="My Marketing" TextWrapping="Wrap" HorizontalAlignment="Center"/>
                                        <TextBlock Text="PDF" TextWrapping="Wrap" HorizontalAlignment="Center"/>
                                    </StackPanel>
                                </HyperlinkButton.Content>
                            </HyperlinkButton>
                        </StackPanel>
                </Grid>
                </Border> 
            </DataTemplate>

     

    search results are applied to the datagrid itemsSource.
  • Ken Tucker

    Ken Tucker

    All-Star

    23250 Points

    3534 Posts

    Re: Datagrid not rendering a row.

    Aug 26, 2009 05:21 PM | LINK

     If you are using silverlight 2 make sure you have the dec 2008 version of the datagrid

    http://silverlight.net/forums/t/59990.aspx

  • Mog Liang - MSFT

    Mog Liang -...

    All-Star

    21645 Points

    2132 Posts

    Microsoft

    Re: Datagrid not rendering a row.

    Aug 31, 2009 06:19 AM | LINK

    Hi, 

    You could set DataGridColumn.IsReadOnly=true to those columns which donot need editing.

    If you don't need editing on datagrid, set DataGrid.IsReadOnly=true would work.

    Thanks,

    Mog Liang
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • cwpecora

    cwpecora

    Member

    1 Points

    8 Posts

    Re: Datagrid not rendering a row.

    Aug 31, 2009 02:01 PM | LINK

     thanks Ken that appears to have fixed it!

  • cwpecora

    cwpecora

    Member

    1 Points

    8 Posts

    Re: Datagrid not rendering a row.

    Aug 31, 2009 02:02 PM | LINK

     I had and have set the datagrid itself and both columns to read only .. that did not help my issue.   it turns out that Ken was right and I was using a pre-December version of the datagrid and updating fixed my issue.