2016-05-19 9 views
1

Я пытаюсь добавить столбец combobox в XCeeds DataGridControl. Удалось сделать CellEditor, который устанавливает правильные значения в поле binded, но есть проблемы с шаблоном CellContent.Как добавить столбец ComboBox в XCeed DataGridControl (WPF)

Xaml:

<Grid> 
    <Grid.RowDefinitions> 
     <RowDefinition></RowDefinition> 
    </Grid.RowDefinitions> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition></ColumnDefinition> 
    </Grid.ColumnDefinitions> 

    <xcdg:DataGridControl ItemsSource="{Binding Address}" > 
     <xcdg:DataGridControl.Columns> 
      <xcdg:Column x:Name="clmAdd" FieldName="HouseNumberAdd"/> 
      <xcdg:Column x:Name="clmCity" FieldName="City"/> 
      <xcdg:Column x:Name="clmCountry" FieldName="CountryID"> 
       <xcdg:Column.CellEditor> 
        <xcdg:CellEditor> 
         <xcdg:CellEditor.EditTemplate> 
          <DataTemplate> 
           <ComboBox SelectedValuePath="CountryID" 
              DisplayMemberPath="Name" 
              ItemsSource="{Binding Path=DataContext.Country, RelativeSource={RelativeSource AncestorType={x:Type Window}}}" 
              SelectedValue="{xcdg:CellEditorBinding}" IsEditable="True" Foreground="Black" IsSynchronizedWithCurrentItem="True" /> 
          </DataTemplate> 
         </xcdg:CellEditor.EditTemplate> 
        </xcdg:CellEditor> 
       </xcdg:Column.CellEditor> 
      </xcdg:Column> 
     </xcdg:DataGridControl.Columns> 
    </xcdg:DataGridControl> 
</Grid> 

Код:

public partial class MainWindow : Window 
{ 
    ViewMode viewMode; 
    public MainWindow() 
    { 
     InitializeComponent(); 

     viewMode = new ViewMode(); 
     this.DataContext = viewMode; 
    } 

    private void Window_MouseDoubleClick(object sender, MouseButtonEventArgs e) 
    { 
     DataTable source = viewMode.Address; 
    } 
} 

public class ViewMode 
{ 
    public DataTable Address { get; set; } 
    public DataTable Country { get; set; } 

    public ViewMode() 
    { 
     Address = new DataTable(); 
     Address.Columns.Add("HouseNumberAdd", typeof(string)); 
     Address.Columns.Add("City", typeof(string)); 
     Address.Columns.Add("CountryID", typeof(int)); 

     Address.Rows.Add("Ivlivensko 10-KV 1234", "Krakov", 1); 
     Address.Rows.Add("Astrakhanski 10-KV 1234", "Kharkiv", 2); 
     Address.Rows.Add("Tverskii 10-KV 1234", "Moskva", 3); 
     Address.Rows.Add("Klement 10-KV 1234", "Warsav", 1); 

     Country = new DataTable(); 
     Country.Columns.Add("Name", typeof(string)); 
     Country.Columns.Add("CountryID", typeof(int)); 

     Country.Rows.Add("Poland", 1); 
     Country.Rows.Add("Ukrain", 2); 
     Country.Rows.Add("Russland", 3); 
    } 
} 

Редакцией::

Я заменил CellEditor на ContentTemplate, но когда я пытаюсь изменить данные внутри Grid, исходная таблица остается s AME. Как я могу это исправить?

<Grid> 
    <Grid.RowDefinitions> 
     <RowDefinition></RowDefinition> 
    </Grid.RowDefinitions> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition></ColumnDefinition> 
    </Grid.ColumnDefinitions> 

    <xcdg:DataGridControl ItemsSource="{Binding Address}" > 
     <xcdg:DataGridControl.Columns> 
      <xcdg:Column x:Name="clmAdd" FieldName="HouseNumberAdd"/> 
      <xcdg:Column x:Name="clmCity" FieldName="City"/> 
      <xcdg:Column x:Name="clmCountry" FieldName="CountryID"> 
       <xcdg:Column.CellContentTemplate> 
        <DataTemplate x:Name="clmCountryTmp"> 
         <ComboBox SelectedValuePath="CountryID" 
           DisplayMemberPath="Name" 
           ItemsSource="{Binding Path=DataContext.Country, RelativeSource={RelativeSource AncestorType={x:Type Window}}}" 
           SelectedValue="{xcdg:CellEditorBinding}"/> 
        </DataTemplate> 
       </xcdg:Column.CellContentTemplate> 
      </xcdg:Column> 
     </xcdg:DataGridControl.Columns> 
    </xcdg:DataGridControl> 
</Grid> 
+0

Непонятно, какие проблемы у вас есть. – StepUp

ответ

2

IsSynchronizedWithCurrentItem="True" Попробуйте удалить

В моих тестах, имея это предотвратить текстовое значение от появления в выпадающем списке при переходе в режим редактирования. Как только я удалю его, текст будет отображаться так, как ожидалось.

Если вы хотите изменить внешний вид ячейки, когда вы не находитесь в режиме редактирования, вы можете назначить в колонке настраиваемый CellContentTemplate.

+0

Thx. Я заменил CellEditor на ContentTemplate, но когда я его редактирую, исходные данные не меняются. Не могли бы вы мне помочь? –

+0

нашел, как исправить это, добавил CellEditorDisplayConditions = "Always" thx –