2011-09-01 20 views
0

我有一個Telerik的gridview的的DisplayMemberPath Telerik的GridViewComboBoxColumn的

<UserControl x:Class="TelerikGridViewComboBoxExample.MainPage" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d" 
    d:DesignHeight="300" d:DesignWidth="400" 
    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"> 

    <Grid x:Name="LayoutRoot" Background="White"> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="143*" /> 
      <RowDefinition Height="157*" /> 
     </Grid.RowDefinitions> 
     <StackPanel Grid.Row="0"> 
      <TextBlock Text="Good Sample"/> 
      <telerik:RadGridView x:Name="radGridView" 
         AutoGenerateColumns="False" ItemsSource="{Binding Peoples}"> 
       <telerik:RadGridView.Columns> 
        <telerik:GridViewComboBoxColumn 
        DataMemberBinding="{Binding CountryID}" 
        UniqueName="Country" 
        SelectedValueMemberPath="Id" 
        DisplayMemberPath="Name"/> 

        <telerik:GridViewDataColumn DataMemberBinding="{Binding FirstName}" UniqueName="First Name"/> 
        <telerik:GridViewDataColumn DataMemberBinding="{Binding LastName}" UniqueName="Last Name"/> 
       </telerik:RadGridView.Columns> 
      </telerik:RadGridView> 
     </StackPanel> 

    </Grid> 
</UserControl> 

,這裏是一個xaml.cs

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Net; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Documents; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Animation; 
using System.Windows.Shapes; 
using System.Collections.ObjectModel; 
using Telerik.Windows.Controls; 

namespace TelerikGridViewComboBoxExample 
{ 
    public partial class MainPage : UserControl 
    { 
     public MainPage() 
     { 
      InitializeComponent(); 
      this.Loaded += new RoutedEventHandler(MainPage_Loaded); 
     } 

     void MainPage_Loaded(object sender, RoutedEventArgs e) 
     { 
      foreach (var x in 
       new People[] { 
       new People { CountryID = 0, FirstName = "Sebastain", LastName = "Vettel" }, 
       new People { CountryID = 1, FirstName = "Fernando", LastName = "Alonso" }, 
       new People { CountryID = 2, FirstName = "James", LastName = "Button" } 
       }) 
      { 
       Peoples.Add(x); 
      } 


      foreach (var x in 
      new Country[] { 
       new Country { Id = 0, Name = "Germany",Nationality = "german"}, 
       new Country { Id = 1, Name = "Spain" ,Nationality = "Spanish"}, 
       new Country { Id = 2, Name = "UK" ,Nationality = "English"} 
       }) 
      { 
       Countries.Add(x); 
      } 

      this.DataContext = this; 
      ((GridViewComboBoxColumn)this.radGridView.Columns["Country"]).ItemsSource = Countries; 
     } 

     private ObservableCollection<People> peoples = new ObservableCollection<People>(); 
     public ObservableCollection<People> Peoples 
     { 
      get { return peoples; } 
      set { peoples = value; } 
     } 

     private ObservableCollection<Country> countries = new ObservableCollection<Country>(); 
     public ObservableCollection<Country> Countries 
     { 
      get { return countries; } 
      set { countries = value; } 
     } 
    } 

    public class People 
    { 
     public int CountryID { get; set; } 
     public string FirstName { get; set; } 
     public string LastName { get; set; } 
    } 

    public class Country 
    { 
     public int Id { get; set; } 
     public string Name { get; set; } 
     public string Nationality { get; set; } 
    } 
} 

一切工作正常,但我想在國家列值國籍來顯示,但作爲現在我想以國家的組合名稱來選擇。

so: 1.用戶點擊國家欄中的行, 2.選擇德國 3.行中的值爲germnan。

如果沒有possilbe,我想有該行的第一,和國家的名稱(例如「GY」)的最後一個字母

我使用2010.1.603.1040版本Silverlight的Telerik的包。

可能嗎?

此致

回答

0

使用開關殼體與由包括在GridView代碼的自定義字段(按鈕)使用行命令,並通過記錄ID(從DB)作爲參數 谷歌「使用.NET行命令」只是語法 然後你可以執行任何你想要執行的動作