2 DB tables is used in the test. One is Product table, another is Category table. Each Product Belong to a Category. A ComboBox is used in a DataForm to display/assign Product.Category.
Product list is displayed in a DataGrid, current SelectedItem is displayed in the DataForm.
Two testing cases:
1) DataForm is in the same page as the DataGrid. The Product Category data of the first row displayed wrong in both DataGrid and in the DataForm. You can see the CategoryId for Product 1 in DB should be 5. But it is shown Category 1 in the DataGrid and
DataForm. Other rows data all displayed correctly, only the first row has this problem.
Go to the code behind, use Code to set ComboBox.ItemsSource as following:
//Remove this line
Combo.ItemsSource = CatData.Data; //When this line is not used, The ComboBox does not display data right for the first row of Product
}
Now test the page again. The Category Data are displayed correctly
2) DataForm is in a ChildWindow.
Click the Edit Button should show a ChildWindow with a DataForm in it. The DataForm.CurrentItem is set to the DataGrid.SelectedItem.
The Category is displayed as Category 1 for all Products even none of the Product belong to Category 1. Not only the Category 1 is shown in the ChildWindow, the wrong data also reflected back to the DataGrid in the main window. As you open the ChildWindow
for each Product, the CategoryID changed to 1 for each Product, even the DataForm in the ChildWindow is not even in Edit mode.
Please tell us what we should do with the ComboBox. Is using static list for ComboBox.ItemsSource the only solution?
Sally Xu
Software Engineer
Aprimo, Inc
Please remember to mark the replies as answers if they answered your question
I tested, and it seems the cause is when DomainDataSource and ComboBox are used together.
The combo box will try to set it's first item as the selectedItem.
Basically , in your first scenerio, the correct data has been loaded, but after it's loaded it's modified by the combo(try to set the first item as selected).
I use a value converter to track. And also ,this could be reproed by a plain use like below:
Kyle thanks for the link, my project "burns bright flame" a dead ComboBox, tired of fighting with broken and just wanted to pass on third-party controls.
I will test your decision and hope for full efficiency.
Alexander G. Bykin
►MCP: Silverlight Developer
►(If I answered your question, please click on "mark as answer" on this post. Thank you!)
sladapter
All-Star
43609 Points
7910 Posts
ComboBox bug in DataForm (Siverlight 4)
Jun 13, 2010 11:47 PM | LINK
Here is a simple Testing project can be downloaded to see the problem of ComboBox used in DataForm.
http://cid-9cffd385fd75195b.office.live.com/self.aspx/Silverlight/ComboBoxTest.zip
2 DB tables is used in the test. One is Product table, another is Category table. Each Product Belong to a Category. A ComboBox is used in a DataForm to display/assign Product.Category.
Product list is displayed in a DataGrid, current SelectedItem is displayed in the DataForm.
Two testing cases:
1) DataForm is in the same page as the DataGrid. The Product Category data of the first row displayed wrong in both DataGrid and in the DataForm. You can see the CategoryId for Product 1 in DB should be 5. But it is shown Category 1 in the DataGrid and DataForm. Other rows data all displayed correctly, only the first row has this problem.
Go to the code behind, use Code to set ComboBox.ItemsSource as following:
private void CatData_LoadedData(object sender, LoadedDataEventArgs e)
{
//Remove this line
Combo.ItemsSource = CatData.Data; //When this line is not used, The ComboBox does not display data right for the first row of Product
}
Now test the page again. The Category Data are displayed correctly
2) DataForm is in a ChildWindow.
Click the Edit Button should show a ChildWindow with a DataForm in it. The DataForm.CurrentItem is set to the DataGrid.SelectedItem.
The Category is displayed as Category 1 for all Products even none of the Product belong to Category 1. Not only the Category 1 is shown in the ChildWindow, the wrong data also reflected back to the DataGrid in the main window. As you open the ChildWindow for each Product, the CategoryID changed to 1 for each Product, even the DataForm in the ChildWindow is not even in Edit mode.
Please tell us what we should do with the ComboBox. Is using static list for ComboBox.ItemsSource the only solution?
Software Engineer
Aprimo, Inc
Please remember to mark the replies as answers if they answered your question
Min-Hong Tan...
All-Star
28750 Points
3295 Posts
Re: ComboBox bug in DataForm (Siverlight 4)
Jun 16, 2010 05:02 AM | LINK
Hi,
Thanks for bring this up.
I tested, and it seems the cause is when DomainDataSource and ComboBox are used together.
The combo box will try to set it's first item as the selectedItem.
Basically , in your first scenerio, the correct data has been loaded, but after it's loaded it's modified by the combo(try to set the first item as selected).
I use a value converter to track. And also ,this could be reproed by a plain use like below:
<my1:DomainDataSource x:Name="cbd" QueryName="GetCategoryQuery" AutoLoad="True" LoadedData="cbd_LoadedData" DomainContext="{StaticResource dbc}">
</my1:DomainDataSource>
<ComboBox ItemsSource="{Binding DataView,ElementName=cbd}"></ComboBox>
After the above code executed , the first item will be selected.
I'll email this, thank you again. And if got anything valuable will post it here.
Best Regards
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
sladapter
All-Star
43609 Points
7910 Posts
Re: ComboBox bug in DataForm (Siverlight 4)
Jun 16, 2010 12:26 PM | LINK
Thanks Min-Hong. Hope it will be fixed in the next release.
Software Engineer
Aprimo, Inc
Please remember to mark the replies as answers if they answered your question
kylemc
Contributor
7243 Points
1147 Posts
Microsoft
Re: ComboBox bug in DataForm (Siverlight 4)
Jun 18, 2010 06:46 PM | LINK
sladapter, I just posted a sample using the ComboBox with RIA Services, DataGrid, and DataForm (http://blogs.msdn.com/kylemc/archive/2010/06/18/combobox-sample-for-ria-services.aspx). It addresses your problem as well as a few others and I really appreciate any feedback you can give.
Kyle
bykinag
Participant
1049 Points
312 Posts
Re: ComboBox bug in DataForm (Siverlight 4)
Jun 19, 2010 08:49 PM | LINK
I will test your decision and hope for full efficiency.
►MCP: Silverlight Developer
►(If I answered your question, please click on "mark as answer" on this post. Thank you!)
kalramanoj2002
Member
2 Points
1 Post
Re: ComboBox bug in DataForm (Siverlight 4)
Feb 20, 2012 06:33 PM | LINK
Is this issue fixed in Silverlight 5?