Click here to Skip to main content
Rate this: bad
good
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 20:30pm
Comments
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
good
Please Sign up or sign in to vote.

Solution 1

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>
  Permalink  
Rate this: bad
good
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">
<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
  Permalink  
v2

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



Advertise | Privacy | Mobile
Web04 | 2.8.150302.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