Click here to Skip to main content
15,310,056 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:
HTML
<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">
           
            <datagrid.columns>
                <datagridtextcolumn header="Hours" binding="{Binding time}" fontsize="14" fontweight="Bold" isreadonly="True" width="100" />


                <datagridtemplatecolumn header="Monday" width="100">
                    <datagridtemplatecolumn.celleditingtemplate>
                        <datatemplate>
                            <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>
                            </stackpanel>
                        </datatemplate>
                       
                    </datagridtemplatecolumn.celleditingtemplate>
                    <datagridtemplatecolumn.celltemplate>
                        <datatemplate>
                            <stackpanel>
                                <textblock x:name="mon" text="{Binding ProductName}" xmlns:x="#unknown"></textblock>
                                </stackpanel> 
                        </datatemplate>
                    </datagridtemplatecolumn.celltemplate>

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

1 solution

Hi,

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,

Shai
   

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