2016-05-19 36 views
1

我想在XCeeds DataGridControl中添加組合框列。管理製作CellEditor,它爲綁定字段設置適當的值,但CellContent模板存在問題。如何在XCeed DataGridControl(WPF)中添加ComboBox列

的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); 
    } 
} 

編輯:

我已經被替換的ContentTemplate CellEditor的,但是當我試圖編輯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。我用ContentTemplate替換了CellEditor,但是當我編輯它時,源數據不會改變。你能幫我解決嗎? –

+0

找到了解決方法,添加了CellEditorDisplayConditions =「Always」thx –

相關問題