系列二
    实现RadGridView行中添加不同控件,并在控件中绑定不同的数据源
    先上一段前台代码

<telerik:RadGridView Grid.Row="2" x:Name="activitiesGrid1"
                              AutoGenerateColumns="False" GridLinesVisibility="None" Visibility="Collapsed"
                              UseLayoutRounding="False"  IsReadOnly="True"
                              RowHeight="20" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" SelectionMode="Single"
                              HorizontalGridLinesBrush="Transparent" VerticalGridLinesBrush="Transparent"
                              Background="{x:Null}" BorderBrush="{x:Null}"
                              IsFilteringAllowed="False" RowIndicatorVisibility="Collapsed"
                              CanUserFreezeColumns="False" ShowGroupPanel="False"
                              HeaderRowStyle="{StaticResource SalesInfoGridViewHeaderRowStyle}"
                              GroupRowStyle="{StaticResource SalesInfoGridViewGroupRowStyle}" 
                              RowStyle="{StaticResource SalesInfoGridViewRowStyle}"
                              ScrollViewer.HorizontalScrollBarVisibility="Auto"
                              ScrollViewer.VerticalScrollBarVisibility="Auto"  Height="200">
                             <telerik:RadGridView.Columns>
                                 <telerik:GridViewColumn Header="归属营业厅ID" Width="*" IsVisible="False">
                                     <telerik:GridViewColumn.CellTemplate>
                                         <DataTemplate>
                                             <TextBlock  Text="{Binding ROOM_ID}" />
                                         </DataTemplate>
                                     </telerik:GridViewColumn.CellTemplate>
                                 </telerik:GridViewColumn>
                                 <telerik:GridViewColumn Header="归属县ID" Width="*" IsVisible="False">
                                     <telerik:GridViewColumn.CellTemplate>
                                         <DataTemplate>
                                             <TextBlock  Text="{Binding TOWN_ID}" />
                                         </DataTemplate>
                                     </telerik:GridViewColumn.CellTemplate>
                                 </telerik:GridViewColumn>
                                 <telerik:GridViewColumn Header="归属营业厅名称" Width="*">
                                     <telerik:GridViewColumn.CellTemplate>
                                         <DataTemplate>
                                             <TextBlock  Text="{Binding ROOM_NAME}" />
                                         </DataTemplate>
                                     </telerik:GridViewColumn.CellTemplate>
                                 </telerik:GridViewColumn>
                                 <telerik:GridViewColumn Header="归属县名称" Width="*">
                                     <telerik:GridViewColumn.CellTemplate>
                                         <DataTemplate>
                                             <TextBlock Text="{Binding COUNTY_NAME}" FontSize="14"  Width="100"/>
                                         </DataTemplate>
                                     </telerik:GridViewColumn.CellTemplate>
                                 </telerik:GridViewColumn>
                                 <telerik:GridViewColumn Header="归属营业厅类型" Width="*">
                                     <telerik:GridViewColumn.CellTemplate>
                                         <DataTemplate>
                                             <telerik:RadComboBox EmptyText="{Binding ROOM_TYPE}"  Width="100" FontSize="14" Text="{Binding  ROOM_TYPE}"
                                                                  HorizontalAlignment="Left" Style="{StaticResource RadComboBoxStyle1}" >
                                                 <telerik:RadComboBoxItem Content="形象厅"  Style="{StaticResource RadComboBoxItemStyle1}" />
                                                 <telerik:RadComboBoxItem Content="市县营业厅"  Style="{StaticResource RadComboBoxItemStyle1}"/>
                                                 <telerik:RadComboBoxItem Content="乡镇营业厅"  Style="{StaticResource RadComboBoxItemStyle1}"/>
                                             </telerik:RadComboBox>
                                         </DataTemplate>
                                     </telerik:GridViewColumn.CellTemplate>
                                 </telerik:GridViewColumn>
                                 <telerik:GridViewColumn Header="创建时间" Width="*">
                                     <telerik:GridViewColumn.CellTemplate>
                                         <DataTemplate>
                                             <TextBlock  Text="{Binding CREATETIME}" />
                                         </DataTemplate>
                                     </telerik:GridViewColumn.CellTemplate>
                                 </telerik:GridViewColumn>
                                 <telerik:GridViewColumn Header="状态" Width="*">
                                     <telerik:GridViewColumn.CellTemplate>
                                         <DataTemplate>
                                             <telerik:RadComboBox EmptyText="{Binding ROOM_STAT}" Text="{Binding ROOM_STAT}" Width="100" FontSize="14"  HorizontalAlignment="Left" Style="{StaticResource RadComboBoxStyle1}" >
                                                 <telerik:RadComboBoxItem Content="正常"  Style="{StaticResource RadComboBoxItemStyle1}" />
                                                 <telerik:RadComboBoxItem Content="异常"  Style="{StaticResource RadComboBoxItemStyle1}"/>
                                             </telerik:RadComboBox>
                                         </DataTemplate>
                                     </telerik:GridViewColumn.CellTemplate>
                                 </telerik:GridViewColumn>
                                 <telerik:GridViewDataColumn DataMemberBinding="{Binding ROOM_DMXS}" Header="营业厅店面调节系数" Width="*" />
                                 <telerik:GridViewColumn Header="是否3人以上营业厅" Width="*">
                                     <telerik:GridViewColumn.CellTemplate>
                                         <DataTemplate>
                                             <telerik:RadComboBox EmptyText="{Binding IS_GREATERTHREE}" Text="{Binding IS_GREATERTHREE}" Width="100"
                                                                  FontSize="14"  HorizontalAlignment="Left" Style="{StaticResource RadComboBoxStyle1}" >
                                                 <telerik:RadComboBoxItem Content="是"  Style="{StaticResource RadComboBoxItemStyle1}" />
                                                 <telerik:RadComboBoxItem Content="否"  Style="{StaticResource RadComboBoxItemStyle1}"/>
                                             </telerik:RadComboBox>
                                         </DataTemplate>
                                     </telerik:GridViewColumn.CellTemplate>
                                 </telerik:GridViewColumn>
                                 <telerik:GridViewColumn Header="" Width="*"     HeaderCellStyle="{StaticResource SalesInfoGridViewHeaderCellStyleFirst}"
                                                         CellStyle="{StaticResource SalesInfoGridViewCellStyle}">
                                     <telerik:GridViewColumn.CellTemplate>
                                         <DataTemplate>
                                             <telerik:RadButton   Style="{StaticResource RadButtonStyle}" Content="删除"
                                                              x:Name="ExceptXishu" Click="ExceptXishu_Click"
                                                              FontSize="12" Foreground="White" 
                                                              Tag="{Binding ID}" 
                                                              Height="20" Width="50"
                                                              />
                                         </DataTemplate>
                                     </telerik:GridViewColumn.CellTemplate>
                                 </telerik:GridViewColumn>
                             </telerik:RadGridView.Columns>
                         </telerik:RadGridView>

在GridViewColumn中添加GridViewColumn.CellTemplate,并在其子节点添加DataTemplate,在其中添加你想要的控件。可以在不同的控件中设置数据源绑定。

我在给RadGridView赋值的时候是通过赋值LIST集合赋值。

例如,this.activitiesGrid.ItemsSource = e.Result.ToList();---此处指的是从服务引用中返回的数据源(大家都懂得)

若你想你的控件在展示的时候默认显示第一行,请添加如下代码:

 if (this.activitiesGrid.Items.Count>)
{
this.activitiesGrid.SelectedItem = activitiesGrid.Items[];
}

在后台控制控件中某一列的显示和隐藏
声明GridViewColumn 对象,取得对象之后控制显示和隐藏

GridViewColumn column = this.activitiesGrid.Columns[第几行];

column.IsVisible = true;//显示这一列

在后台取得某一行的数据源

(在这里我用了一个技巧,在给RadGridView绑定数据源的同时,我给每一个行的数据源绑定了一个ID,是为了取得每一个行的数据源)

在RadGridView控件中,每一行我定义一个控件,例如是RadButton控件,在他的Tag属性中我绑定了这一行数据源的ID,点击事件后我将这行的ID取出,然后可以得到其数据源,前后台代码如下:

前台代码:

<telerik:GridViewColumn Header="删除" Width="*"     HeaderCellStyle="{StaticResource SalesInfoGridViewHeaderCellStyleFirst}"
                                                         CellStyle="{StaticResource SalesInfoGridViewCellStyle}">
                                 <telerik:GridViewColumn.CellTemplate>
                                     <DataTemplate>
                                         <telerik:RadButton   Style="{StaticResource RadButtonStyle}" Content="删除"
                                                              FontSize="12" Foreground="White" 
                                                              Tag="{Binding ID}" 
                                                              Height="20" Width="50"
                                                              Click="RadButton_Click_2" />
                                     </DataTemplate>
                                 </telerik:GridViewColumn.CellTemplate>
                             </telerik:GridViewColumn>

后台代码:

  private void btDeny_Click(object sender, RoutedEventArgs e)
{
RadButton btn = sender as RadButton;
int num = Convert.ToInt32(btn.TabIndex.ToString());
GridViewRow row=new GridViewRow();
var item = this.BackUserDetailes.Items[num];//绑定数据源的同时,给从库中返回的数据源制定了ID
row=this.BackUserDetailes.ItemContainerGenerator.ContainerFromItem(item) as GridViewRow;
//得到Row对象后可以将其的数据源转换成你想要的类型
想要的类型=row.DataContext as 想要的类型;
}

也可以用另外一种简单的方式获得这一行的数据源
想要的类型=btn.DataContext as 想要的类型。

在后台获取行中有不同控件值的方法

取得了GridViewRow对象之后,可以取得这一行的每个单元格,即可把单元格中的控件取出。代码如下:

例如,你在这一单元格中放置的是RadComboBox控件,可以通过:RadComboBox box=row.Cells[第几个单元格].Content as RadComboBox;将RadComboBox对象取出,并进行你想要的操作。

在RadGridView中对某一列的特殊的控件赋值,通过这一列的控件中声明其Loaded事件,为这一行的特殊的控件赋值。

例如下例:

<telerik:GridViewColumn Header="给特殊列绑定单个数据" Width="*"     HeaderCellStyle="{StaticResource SalesInfoGridViewHeaderCellStyleFirst}"
                                                         CellStyle="{StaticResource SalesInfoGridViewCellStyle}" >
                                 <telerik:GridViewColumn.CellTemplate>
                                     <DataTemplate>
                                         <telerik:RadComboBox EmptyText="{Binding 绑定的数据源中字段名称}"  Text="{Binding 绑定的数据源中字段名称}"
                                                              FontSize="14" Width="200" HorizontalAlignment="Left"
                                                              Style="{StaticResource RadComboBoxStyle1}"   
                                                              Loaded="RadComboBox_Loaded">
                                             <telerik:RadComboBoxItem Content="{Binding 绑定的数据源中字段名称}" Tag="{Binding CHNL_ID}" Style="{StaticResource RadComboBoxItemStyle1}" />
                                         </telerik:RadComboBox>
                                     </DataTemplate>
                                 </telerik:GridViewColumn.CellTemplate>
                             </telerik:GridViewColumn>

其中,EmptyText="{Binding 绑定的数据源的名称}"指的是其RadComboBox在没有 默认显示第一个值时的赋予该控件的值。
后台代码如下:

private void RadComboBox_Loaded(object sender, RoutedEventArgs e)
         {
             RadComboBox box = sender as RadComboBox;
             box.Items.Clear();
             (sender as RadComboBox).DisplayMemberPath = "ROOM_NAME";
             (sender as RadComboBox).Tag = this.chnlList[0].ROOM_ID;
             (sender as RadComboBox).ItemsSource = 数据源名称;          
             box.ItemsSource = chnlList;
         }


silverlight RadGridView总结二(转载)的更多相关文章

  1. silverlight RadGridView总结三(转载)

    在RadGridView中进行分组以及导出 分组 主要是在前台进行分组的定义: 前台代码: <telerik:RadGridView x:Name="RadGridView1" ...

  2. silverlight RadGridView总结系列(转载)

    系列一. RadGridView常用属性总结    1.不可编辑----IsReadOnly="True".    2.不自动增加行----AutoGenerateColumns= ...

  3. SilverlightOA源代码(可用于企业级Silverlight项目的二次开发,长年有效)

    Silverlight OA系统简介 系统功能简介 l 程序界面介绍: 左侧为主菜单,主菜单可以展开和收起,主菜单下面的所有模块都可以在数据库中扩展增加,模块的权限和用户角色挂钩,可以在数据库中创建多 ...

  4. SilverLight.3-Validation:二、银光验证。TheLabel、TheDescriptionViewer和TheValidationSummary

    ylbtech-SilverLight.3-DataControls_BetterDataFroms:二.银光验证.TheLabel.TheDescriptionViewer和TheValidatio ...

  5. Silverlight RadGridView的HeaderCellStyle样式

    效果图 <UserControl x:Class="SilverlightApplication7.MainPage" xmlns="http://schemas. ...

  6. PCB优化设计(二) 转载

    PCB优化设计(二) 2011-04-25 11:41:05|  分类: PCB设计   目 前SMT技术已经非常成熟,并在电子产品上广泛应用,因此,电子产品设计师有必要了解SMT技术的常识和可制造性 ...

  7. Silverlight学习(二)

    好久没来写博客了,这期间经历了春节,也因为忙于一个项目,所以博客被疏忽了.最近一段时间一直在用silverlight做项目,从来一开始的不熟悉渐渐的开始上手.今天记录一下自己学习prism的一些sam ...

  8. Fiddler实战深入研究(二)[转载]

    Fiddler实战深入研究(二) 阅读目录 Fiddler不能捕获chrome的session的设置 理解数据包统计 请求重定向(AutoResponder) Composer选项卡 Filters选 ...

  9. Spring WebSocket入门(二) 转载

    本文转载自:http://www.jianshu.com/p/8500ad65eb50 WebSocket前端准备 前端我们需要用到两个js文件:sockjs.js和stomp.js SockJS:S ...

随机推荐

  1. fastxml Jackson annotation使用小记

    dependencies: compile("com.fasterxml.jackson.core:jackson-annotations") compile("com. ...

  2. uva10256

    uva10256 题意 平面上存在两种颜色的点,问是否存在一条直线,使得任取一个红点和一个蓝点都在直线的异侧,这条直线不经过任何点. 分析 对每种颜色的点求一发凸包,问题等价于判断两个多边形是否相交或 ...

  3. Difference between [0-9], [[:digit:]] and \d

    Yes, it is [[:digit:]] ~ [0-9] ~ \d (where ~ means aproximate).In most programming languages (where ...

  4. thinkpad win8.1 无线连接受限

    把博通的驱动回滚到6.30.223.102就好了

  5. 【记忆化搜索】bzoj1055 [HAOI2008]玩具取名

    f(l,r,c)表示sl...sr能否被合成字符c. #include<cstdio> #include<cstring> using namespace std; int m ...

  6. 【博弈论】【SG函数】hdu1848 Fibonacci again and again

    某个状态的SG函数被定义为 除该状态能一步转移到的状态的SG值以外的最小非负整数. 有如下性质:从SG值为x的状态出发,可以转移到SG值为0,1,...,x-1的状态. 不论SG值增加与否,我们都可以 ...

  7. .NET反编译

    http://www.cnblogs.com/powertoolsteam/archive/2011/01/05/1926066.html

  8. [JQuery]用InsertAfter实现图片走马灯展示效果2——js代码重构

    写在前面 前面写过一篇文章<[JQuery]用InsertAfter实现图片走马灯展示效果>,自从写过那样的也算是使用面向对象的写法吧,代码实在丑陋,自从写过那样的代码,就是自己的一块心病 ...

  9. XAMPP安装与多虚拟目录地址设置

    前端开发集成环境-XAMPP 在前端开发中,经常需要进行请求的调试等都需要一个服务器环境,这时类似wamp.XAMPP就是我们最后的选择,集成apache.php.mysql等一应俱全,不需要去单独配 ...

  10. htc支持CSS3

    <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8&quo ...