wpf set the content of datagrid's selected templatecolumn's textbox
Asked Answered
V

0

2

I need to find out how to pass a string to ComboBox that's inside of a TemplateColumn of a DataGrid. The idea behind is that whenever I double-click on a TextBox a Popup appears and I select the new content of the TextBox from it (ComboBox inside a Popup).

XAML

<DataGridTemplateColumn Header="unit">
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <TextBox Text="{Binding unit}" MouseDoubleClick="TextBox_MouseDoubleClick_1" />
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

<!-- The columns in the grid are binded to DataTable-->

<!-- Popup -->
<Popup Name="unitpop" StaysOpen="True" VerticalOffset="-20" HorizontalOffset="30" Placement="Mouse" >
    <Grid Width="100" Height="20" Background="Transparent" >
        <ComboBox x:Name="unit_combo" ItemsSource="{Binding Source={StaticResource UnitListData}}"  DisplayMemberPath="Name" SelectedValuePath="idunit" IsReadOnly="True" SelectionChanged="unit_combo_SelectionChanged" />
    </Grid>
</Popup>

<!-- The ComboBox is binding an ObservableCollection -->
Vying answered 8/6, 2013 at 7:26 Comment(6)
Why don't you use a ComboBox instead of TextBox in your CellTemplate? In this way, user could select the value directly and no Popup is needed.Undertrump
I don't think it is much of a help to just recommend using something else. Apparently if I am asking this question I have a reason not to use ComboBox inside of a TemplateColumn. Not trying to be rude, just saying.Vying
Never mind. I am just trying to find another way to solve the problem. You know, we may get stuck by ourselves sometimes when trying to find a solution which is quite apparent for someone else. :)Undertrump
Please see my answer: #16998451. I hope this helps.Olein
It works, the only problem is that I get only the first one that I click on. Do you have any idea how to fix it? (I put the code into SelectionChanged event)Vying
I had forgotten that in this case will return only the first row. Please see my edit.Olein

© 2022 - 2024 — McMap. All rights reserved.