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 -->
Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
boo_boo_bear
  • 189
  • 1
  • 4
  • 14
  • 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. – Colin Jun 08 '13 at 07:35
  • 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. – boo_boo_bear Jun 08 '13 at 08:36
  • 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. :) – Colin Jun 08 '13 at 11:47
  • 1
    Please see my answer: http://stackoverflow.com/questions/16997951/how-to-access-datagrid-template-column-textbox-text-wpf-c-sharp. I hope this helps. – Anatoliy Nikolaev Jun 08 '13 at 15:24
  • 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) – boo_boo_bear Jun 08 '13 at 16:44
  • 1
    I had forgotten that in this case will return only the first row. Please see my edit. – Anatoliy Nikolaev Jun 08 '13 at 19:32

0 Answers0