Skip to main content
Home Forums General Silverlight New Features in Silverlight 3 datagrid error when tabing to next row
4 replies. Latest Post by logindude on July 4, 2009.
(0)
logindude
Member
0 points
3 Posts
06-18-2009 1:18 PM |
I have a datagrid with 5 columns, and 3 rows, and the item in the first columns on each row is a combo box. When i tab through the cells and get to the next row the combo box is disabled and looses it's settings. is this a bug that's going to be fixed in silverlight3?
yifung
Contributor
3313 points
540 Posts
06-18-2009 9:44 PM |
How are you adding the ComboBox to the DataGrid, and how are you populating it?
06-23-2009 12:09 PM |
This is most of the code for the combobox. I use a webservice to get all the articles i need and then i set the itemssource.
1 <Grid Margin="8,200,8,51"> 2 <data:DataGrid x:Name="ordrelinjerDatagrid" AutoGenerateColumns="False" CanUserSortColumns="False" SelectionMode="Single" GridLinesVisibility="All" RowDetailsTemplate="{StaticResource orderrowsdetailTemplate}" ItemsSource="{Binding Path=ordrelinjeliste}" TabNavigation="Cycle" TabIndex="12" > 3 <data:DataGrid.Columns> 4 <data:DataGridTemplateColumn Header="Artikler" MinWidth="200"> 5 <data:DataGridTemplateColumn.CellEditingTemplate> 6 <DataTemplate> 7 <ComboBox Loaded="ComboBox_Loaded" SelectionChanged="ComboBox_SelectionChanged" IsEnabledChanged="ComboBox_IsEnabledChanged"> 8 <ComboBox.ItemTemplate> 9 <DataTemplate> 10 <StackPanel Margin="0,3,0,3"> 11 <StackPanel Orientation="Horizontal"> 12 <TextBlock Text="{Binding Path=ART_ArticleNo, Mode=TwoWay}" HorizontalAlignment="Right" VerticalAlignment="Center" FontSize="10" Width="60" /> 13 <TextBlock Text="{Binding Path=ART_Name, Mode=TwoWay}" Foreground="DarkRed" FontSize="10" HorizontalAlignment="Right" /> 14 </StackPanel> 15 16 </StackPanel> 17 </DataTemplate> 18 </ComboBox.ItemTemplate> 19 </ComboBox> 20 </DataTemplate> 21 </data:DataGridTemplateColumn.CellEditingTemplate> 22 </data:DataGridTemplateColumn> 23 <data:DataGridTextColumn Header="Artikkelnavn" Binding="{Binding Path=COL_Name, Mode=TwoWay}" MinWidth="350" /> 24 <data:DataGridTextColumn Header="Nto. pris" Binding="{Binding Converter={StaticResource FormatConverter}, ConverterParameter=\{0:c\}, Path=COL_NetPrice, Mode=TwoWay}" /> 25 <data:DataGridTextColumn Header="Antall" Binding="{Binding Converter={StaticResource FormatConverter}, ConverterParameter=\{0:c\}, Path=COL_Quantity, Mode=TwoWay}" /> 26 <data:DataGridTextColumn Header="Beløp" Binding="{Binding Converter={StaticResource FormatConverter}, ConverterParameter=\{0:c\}, Path=COL_Amount, Mode=TwoWay}" IsReadOnly="True" MinWidth="56" /> 27 </data:DataGrid.Columns> 28 </data:DataGrid> 29 </Grid> 30 31 32 vb.net code: 33 Sub hentArtikler(ByVal sender As Object, ByVal e As getArticleAllCompletedEventArgs) 34 If String.IsNullOrEmpty(e.Result(0).ART_ArticleNo.ToString) = False Then 35 If articles.Count <= 0 Then 36 articles = e.Result.ToList 37 End If 38 For Each index As ComboBox In comboboxlist 39 index.ItemsSource = articles 40 index.IsEnabled = True 41 Next 42 End If 43 End Sub
I tryed another approach which is a little better, but when i tab throu the list if i'm in edit mode of the datagrid, the combobox item is not seletected when i continue tabbing.
1 <Grid x:Name="LayoutRoot" Background="White" DataContext="{Binding Source={StaticResource personerlisteDataSource}}"> 2 <Grid.RowDefinitions> 3 <RowDefinition Height="*"/> 4 </Grid.RowDefinitions> 5 <data:DataGrid x:Name="mydatagrid" Margin="8,0,0,0" ItemsSource="{Binding}" AutoGenerateColumns="False"> 6 <data:DataGrid.Columns> 7 <data:DataGridTemplateColumn Header="etternavn"> 8 <data:DataGridTemplateColumn.CellTemplate> 9 <DataTemplate> 10 <ComboBox ItemsSource="{Binding personerliste,Mode=TwoWay}" DisplayMemberPath="Fornavn" Loaded="ComboBox_Loaded"/> 11 </DataTemplate> 12 </data:DataGridTemplateColumn.CellTemplate> 13 <data:DataGridTemplateColumn.CellEditingTemplate> 14 <DataTemplate> 15 <ComboBox ItemsSource="{Binding personerliste,Mode=TwoWay}" DisplayMemberPath="Fornavn" Loaded="ComboBox_Loaded"/> 16 </DataTemplate> 17 </data:DataGridTemplateColumn.CellEditingTemplate> 18 </data:DataGridTemplateColumn> 19 <data:DataGridTextColumn Header="Etternavn" Binding="{Binding Path=Etternavn}"/> 20 <data:DataGridTextColumn Header="Fornavn" Binding="{Binding Path=Fornavn}"/> 21 <data:DataGridTextColumn Header="Født" Binding="{Binding Path=Født}"/> 22 </data:DataGrid.Columns> 23 </data:DataGrid> 24 </Grid>
06-25-2009 3:42 PM |
In the 2nd version, if you're binding the ComboBox's SelectedItem to a property in your entity for ComboBoxes then it should retain the selection. What happens when you tab to the next column is the cell is no longer editing so it switches from the editing template to the readonly template. In your case, it creates a new ComboBox. I would actually use a TextBlock for the CellTemplate instead of a ComboBox or disable the ComboBox since the CellTemplate is meant to be a readonly template. That's the general guideline, but of course you may require a certain behavior.
07-04-2009 2:36 PM |
Added property for selecteditem and used it in the celltemplate without any luck. http://asgeirand.net/dg/delmedatagridtestpage.aspx this is just a sample, i'm trying to use the same functionality in one of the applications at work. so it's pretty important for me to get this to work. this is the line i use: --> also tryed with a textbox without any luck. could you please give me a working code example?