Click here to Skip to main content
15,946,988 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hi i am using combobox inside datagrid and the combobox is in cellediting template
i just want to bind the selected item in the combobox to textblock inside the datgrid
if any knows how to do it help me here is my xaml:
<datagrid autogeneratecolumns="False" virtualizingstackpanel.isvirtualizing="False" grid.row="1" grid.columnspan="7" name="attendancegrid" removed="#FFDCE8EB" canuseraddrows="False">
                  BorderBrush="Chocolate" BorderThickness="5" RowHeight="30" IsSynchronizedWithCurrentItem="True"  HorizontalGridLinesBrush="#FFB74646" IsReadOnly="False" Foreground="Black" Loaded="attendancegrid_Loaded" SelectionChanged="attendancegrid_SelectionChanged" CurrentCellChanged="attendancegrid_CurrentCellChanged" CellEditEnding="attendancegrid_CellEditEnding">
                <datagridtextcolumn header="Hours" binding="{Binding time}" fontsize="14" fontweight="Bold" isreadonly="True" width="100" />

                <datagridtemplatecolumn header="Monday" width="100">
                            <stackpanel orientation="Horizontal">
                                <combobox x:name="monday" width="50" selectedvalue="{Binding ProductName, Mode=TwoWay}" issynchronizedwithcurrentitem="true" loaded="monday_Loaded" selectionchanged="monday_SelectionChanged" xmlns:x="#unknown"></combobox>
                                <combobox x:name="staff" width="50" loaded="staff_Loaded" xmlns:x="#unknown"></combobox>
                                <textblock x:name="mon" text="{Binding ProductName}" xmlns:x="#unknown"></textblock>

                <Style TargetType="DataGridColumnHeader">
                    <setter property="FontSize" value="15" />
                    <setter property="FontWeight" value="Bold" />
                    <setter property="Foreground" value="Chocolate" />
                    <setter property="HorizontalContentAlignment" value="Center" />
Updated 7-Oct-13 22:43pm

1 solution


First, I don't understand why are you using DataGrid? You can create a much more simple solution using ItemsControl.

Second, You are trying to implement a Master-Detail pattern. The Combo-Box selected value is the Master and the TextBlock is the Details.

I've wrote a simple example that do exactly what you want to do in my article:

How to: Use the Master-Detail Pattern with WPF Hierarchical DataTemplate[^]

Please review it. If you have more questions I'll be happy to help.

Best Regards,

Share this answer

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