使用可排序集合的datagrid中的组合框 [英] Combobox in datagrid using sortable collection
问题描述
我正在使用silverlight DataGrid. DataGrid的数据源是SortableCollection.
网格在TemplateColumn中包含ComboBox,使用DataContext将数据添加到组合框.
在Grid_LoadingRow事件中,我们正在执行以下操作:
lcmb是combobox.
lControlDs是数据源.
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)
问题是,按预期将行添加到SortableCollection时,将行添加到DataGrid中,但是从单个ComboBox选择值时,对于同一TemplateColumn中的所有其他ComboBox都选择了相同的值.
简而言之,单一选择会影响所有其他组合框.
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?
推荐答案
埃里克
XAML的代码:
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>
好吧,桑特,我想这就是我所能获得的:
我的问题实际上是在ListView中,但我仍然认为它会适用.
我最终得到了以下可工作的XAML
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>
我认为部分问题可能是第二个数据模板-或更像您建议的那样:问题可能出在两个不同组合框使用相同的源,其中一个不在网格模板中,导致选择了一个反映在其中的组合框全部.
这是我的镜头-希望您能解决它.
干杯
埃里克(Erik)
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
这篇关于使用可排序集合的datagrid中的组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!