Click here to Skip to main content
15,891,908 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Comments
Erik Rude 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 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 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 31-Jul-12 4:47am    
Please also share the XAML definition of your grid (if it exists in XAML
sant.rajas 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.

Hi erik

CODE FOR XAML :

<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:datagrid.columns>
              <sdk:datagridtextcolumn canuserreorder="True" canuserresize="True" canusersort="True">
                                      Header="Sr.No" Width="2*"  Binding="{Binding Path=[ServiceRqstDetailRowId]}"  />

              <sdk:datagridtemplatecolumn header="Service Name">
                  <sdk:datagridtemplatecolumn.celltemplate>
                      <datatemplate>
                          <combobox x:name="cmbService" xmlns:x="#unknown">
                              <combobox.itemtemplate>
                                  <datatemplate>
                                      <textblock x:name="txtServiceName" text="{Binding Path=[ServiceShortName]}" />
                                  </datatemplate>
                              </combobox.itemtemplate>
                          </combobox>

                      </datatemplate>
                  </sdk:datagridtemplatecolumn.celltemplate>
              </sdk:datagridtemplatecolumn>

          </sdk:datagridtextcolumn></sdk:datagrid.columns>
      </sdk:datagrid>
 
Share this answer
 
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
HTML
<gridviewcolumn header="Gravity Model ID" displaymemberbinding="{Binding Path=GravityModel.Definition.IDGravityModel}" /><gridviewcolumn header="Gravity Model">
<gridviewcolumn.celltemplate>
    <datatemplate>
      <combobox name="cbxGravityModels" itemssource="{Binding Path=GravityModels}">
        SelectedValuePath="Definition.IDGravityModel"
        SelectedValue="{Binding Path=GravityModel.Definition.IDGravityModel}" 
        DisplayMemberPath="Definition.Name">
      </combobox>
    </datatemplate>
  </gridviewcolumn.celltemplate>
</gridviewcolumn>


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.
Cheers
Erik
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900