Once I click on the button i am getting this error.
This is my code
<sdk:DataGrid MinHeight="100" x:Name="dgCounty" AutoGenerateColumns="False"
VerticalAlignment="Top" IsReadOnly="True" Margin="5,5,5,0"
RowDetailsVisibilityChanged="dgCounty_RowDetailsVisibilityChanged"
RowDetailsVisibilityMode="VisibleWhenSelected">
<sdk:DataGrid.Columns>
<data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Content="+" Click="Button_Click"></Button>
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
<sdk:DataGridTextColumn Header="Countryname" Width="100"
Binding="{Binding Region Name}" CanUserReorder="False"/>
<sdk:DataGridTextColumn Header="Populution" Width="80"
Binding="{Binding Number Of People}" CanUserReorder="False"/>
</sdk:DataGrid.Columns>
<sdk:DataGrid.RowDetailsTemplate>
<DataTemplate>
<sdk:DataGrid x:Name="dgrdRowDetail" Width="400" AutoGenerateColumns="False"
HorizontalAlignment="Center" IsReadOnly="True" Grid.Row="1">
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn Header="county" Binding="{Binding CompanyName}" />
<sdk:DataGridTextColumn Header="Number Of People" Binding="{Binding CompanyID}"/>
</sdk:DataGrid.Columns>
</sdk:DataGrid>
</DataTemplate>
</sdk:DataGrid.RowDetailsTemplate>
</sdk:DataGrid>
code:-
private void Button_Click(object sender, RoutedEventArgs e)
{
Button btnExpandCollapse = sender as Button;
var Row = DataGridRow.GetRowContainingElement(sender as FrameworkElement);
if (Row.DetailsVisibility == Visibility.Collapsed)
{
Row.DetailsVisibility = Visibility.Visible;
}
else
{
Row.DetailsVisibility = Visibility.Collapsed;
}
if (btnExpandCollapse.Content.ToString() == "+")
{
btnExpandCollapse.Content = "-";
}
else if (btnExpandCollapse.Content.ToString() == "-")
{
btnExpandCollapse.Content = "+";
}
}
void dtg_RowDetailsVisibilityChanged(object sender, DataGridRowDetailsEventArgs e)
{
DataGrid RowDetails = e.DetailsElement as DataGrid
if(RowDetails.YourDesiciveFlag = true)
{
}
else
{
}
}
}
Working on this issue from past 3 days any idea how to solve this issue. just going mad on this issue. for expand /collpase in data grid in silverlight.
Let me know if you people can provide me any code that can solve my issue.
thanks in advance prince