Click here to Skip to main content
11,806,026 members (61,608 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: Silverlight combobox DataGrid , +
I am using silverlight DataGrid. DataSource for the DataGrid is SortableCollection.
Grid contains ComboBox in TemplateColumn, using DataContext data is added to combobox.

In Grid_LoadingRow event we are doing the following:
lcmb is combobox.
lControlDs is DataSource.

lCmb.ItemsSource = lControlDS.cDataSourceRowCollection;
lCmb.SelectedValuePath = "[" + lControlDS.lObjControlMappingInfo.SelectedValuePath + "]";
Binding lBinding = new Binding();
lBinding.Source = e.Row.DataContext;
lBinding.Path = new PropertyPath("[" + lControlDS.lObjControlMappingInfo.cControlPropertyMapping[0].RefPropertyName + "]");
lBinding.Mode = BindingMode.TwoWay;
lCmb.SetBinding(ComboBox.SelectedValueProperty, lBinding)

The problem is, on adding a row to SortableCollection as expected Row gets added to DataGrid, but on selecting value from single ComboBox, for all other ComboBoxes in same TemplateColumn same value gets selected.
I short, single selection is affecting all the other comboboxes.

How to handle this problem, and manage to select/show different value in other comboboxes?
Posted 29-Jul-12 19:30pm
Erik Rude at 30-Jul-12 7:44am
I remember having a similar issue some years back in WPF. It has to do with how the Template is being applied. I can't quite remember how It was fixed. I'll see if I can find it somewhere in the back of my mind.
Is this a problem only after you add a new row - or also before?
sant.rajas at 30-Jul-12 10:11am
Initially there is just one row in DataGrid, so the problem is not evident at this point. But when I add a new row, problem arises.

I cant check whether problem exists or not with only single row is present in datagrid, So I am assuming that problem occurs when new row is added.
Erik Rude at 31-Jul-12 4:44am
See if you can make a small project that has just a grid with the same or similar layout with more than one row in. (I assume this is the same in WPF as in Silverlight). If you can replicate in a small sized project it may be easier to solve and get help. I'll see what I can dig out from old projects. Please tell the version of VS and Silverlight.
Erik Rude at 31-Jul-12 4:47am
Please also share the XAML definition of your grid (if it exists in XAML
sant.rajas at 31-Jul-12 5:05am
I used two comboboxes placed outside the datagrid, with same DataSource assigned to both. In this case also I faced similar problem. So I think the problem is not with DataGrid but with use of multiple ComboBoxes and single DataSource.
sant.rajas at 31-Jul-12 5:05am
I have submitted the XAML code for DataGrid.
Erik Rude at 31-Jul-12 5:18am
You should use the Improve Question button instead of supplying a Solution I guess.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Hi erik


<sdk:datagrid autogeneratecolumns="False" height="100" horizontalalignment="Left" margin="75,80,0,0" name="dataGrid1" verticalalignment="Top" width="231" loadingrow="dataGrid1_LoadingRow" xmlns:sdk="#unknown">
              <sdk:datagridtextcolumn canuserreorder="True" canuserresize="True" canusersort="True">
                                      Header="Sr.No" Width="2*"  Binding="{Binding Path=[ServiceRqstDetailRowId]}"  />
              <sdk:datagridtemplatecolumn header="Service Name">
                          <combobox x:name="cmbService" xmlns:x="#unknown">
                                      <textblock x:name="txtServiceName" text="{Binding Path=[ServiceShortName]}" />
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Ok Sant, I think this is what I've got and what I can get:
My issue actually was in a ListView, but I still think it would apply.
I ended up with the following working XAML
<gridviewcolumn header="Gravity Model ID" displaymemberbinding="{Binding Path=GravityModel.Definition.IDGravityModel}" /><gridviewcolumn header="Gravity Model">
      <combobox name="cbxGravityModels" itemssource="{Binding Path=GravityModels}">
        SelectedValue="{Binding Path=GravityModel.Definition.IDGravityModel}" 

I think part of you problem could be the second datatemplate - or more likely as you suggested: The problem may lie in using the same source for two different comboboxes one of which is not in the grid template leading to a selection in one reflecting in them all.
This is my shot - hope you sort it out.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Richard Deeming 225
1 OriginalGriff 215
2 Sergey Alexandrovich Kryukov 170
3 Abhinav S 120
4 ppolymorphe 115
0 OriginalGriff 3,330
1 Maciej Los 1,990
2 KrunalRohit 1,907
3 CPallini 1,905
4 Richard MacCutchan 1,227

Advertise | Privacy | Mobile
Web04 | 2.8.151002.1 | Last Updated 31 Jul 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100