telerik GridViewComboBoxColumn 的 DisplayMemberPath
我有一个 telerik gridview
<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; }
}
}
一切正常,但我想在国家列值中显示国籍,但现在我想在国家的组合名称中进行选择。
所以 : 1. 用户点击 Country 列中的行, 2.选择德国 3.行中的值是德语。
如果不可能,我想在该行中首先显示国家名称的最后一个字母(例如“gy”),
我正在使用 2010.1.603.1040 版本的 Telerik silverlight pack。
是否可以?
此致
I have a telerik gridview
<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>
and here is a 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; }
}
}
Everything works ok, but I want to display in countries column value Nationality, but as now I want in combo names of countries to choose.
so :
1. user clicks at row in Country column ,
2. selects Germany
3.value in row is Germnan.
if it is not possilbe, I want to have in that row first, and last letter of name of country(for example "gy")
I'm using 2010.1.603.1040 version of telerik silverlight pack.
Is it possible?
Best regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过在 gridview 代码中包含自定义字段(按钮)并通过记录 id(来自 db)作为参数来使用 switch case 和 row 命令
谷歌“.net 中的行命令”仅查看语法
然后你就可以执行你想要执行的任何操作
use switch case with using row command by including a custom field(button) in the gridview code and pass record id(from db) as the argument
google "row command in .net" for just syntax
then you can perform whatever action you wish to perform