2016-05-19 3 views
1

XCeeds DataGridControlにコンボボックス列を追加しようとしています。バインドされたフィールドに適切な値を設定するCellEditorを管理しますが、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); 
    } 
} 

EDITED:

私はContentTemplateでcellEditorを置き換えてきましたが、私は、編集しようとしているときグリッド内のデータ、ソーステーブルは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 = "常に" thx –

関連する問題