DataGrid行详细信息的绑定--DataGrid.RowDetailsTe(转载)
2013-06-25 18:00
369 查看
在Silverlight中的DataGrid控件使用中我们想点击其中一行并且看这一行的详细信息应该如何做呢?而且这个详细信息是多行的数据,而非简单的几个属性。 在这里我们使用DataGrid.RowDetailsTemplate来设置或者获取行详细信息。首先我们准备一个DataGrid命名为A,设置其RowDetailsVisibilityMode=VisibleWhenSelected (行详细信
在Silverlight中的DataGrid控件使用中我们想点击其中一行并且看这一行的详细信息应该如何做呢?而且这个详细信息是多行的数据,而非简单的几个属性。
在这里我们使用DataGrid.RowDetailsTemplate来设置或者获取行详细信息。首先我们准备一个DataGrid命名为A,设置其RowDetailsVisibilityMode="VisibleWhenSelected" (行详细信息模板的显示模式是当这行被选中的时候展开这行的详细信息。)然后再为A设置DataGrid.RowDetailsTemplate模板,并且在这个模板中添加一个DataGrid命名为B,这就是前台的XAML代码,在后台中我们设置一个实体集AList绑定到A的DataGrid,然后在AList实体集中有一个属性是BList,这个就是多行的详细信息。将BList详细信息字段绑定到B的DataGrid控件的ItemsSource即可。
下面我们来看看这个简单的应用技巧的Xaml代码如下:
<Grid x:Name="LayoutRoot" Background="White">
<!--这里是第一个DataGrid,其DataGrid.RowDetailsTemplate模板会绑定另外一个DataGrid以显示其详细信息-->
<sdk:DataGrid x:Name="gridEmployee" CanUserReorderColumns="False" CanUserSortColumns="False"
RowDetailsVisibilityMode="VisibleWhenSelected"
HorizontalAlignment="Center" ScrollViewer.VerticalScrollBarVisibility="Auto"
Height="200" AutoGenerateColumns="False" Width="422" VerticalAlignment="Center">
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn Width="150"
Header="用户名"
Binding="{Binding UserName}"/>
<sdk:DataGridTextColumn Width="150"
Header="用户密码"
Binding="{Binding UserPwd}"/>
</sdk:DataGrid.Columns>
<sdk:DataGrid.RowDetailsTemplate>
<DataTemplate>
<!--这里是第二个DataGrid显示详细信息-->
<sdk:DataGrid AutoGenerateColumns="False" ItemsSource="{Binding UserDetailInfomation}"
HeadersVisibility="None">
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn Width="100"
Header="地址"
Binding="{Binding UserAddress}"/>
<sdk:DataGridTextColumn Width="100"
Header="城市"
Binding="{Binding UserCity}"/>
<sdk:DataGridTextColumn Width="100"
Header="国籍"
Binding="{Binding UserCountry}"/>
<sdk:DataGridTextColumn Width="100"
Header="类型"
Binding="{Binding UserState}"/>
</sdk:DataGrid.Columns>
</sdk:DataGrid>
</DataTemplate>
</sdk:DataGrid.RowDetailsTemplate>
</sdk:DataGrid>
</Grid>
然后我们来看看他的数据源的Xaml.cs代码如下:
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
this.gridEmployee.ItemsSource = new UserInfo().GetEmployeeData();
}
}
/// <summary>
/// 用户信息
/// </summary>
public class UserInfo
{
public string UserName { get; set; }
public string UserPwd { get; set; }
/// <summary>
/// 用户详细信息
/// </summary>
public List<UserDetailInfo> UserDetailInfomation{get;set;}
public UserInfo()
{ }
/// <summary>
/// 获取用户信息的实例
/// </summary>
/// <returns></returns>
public List<UserInfo> GetEmployeeData()
{
List<UserInfo> employees = new List<UserInfo>();
employees.Add
(
new UserInfo
{
UserName = "李伟",
UserPwd = "1333821",
UserDetailInfomation = new List<UserDetailInfo>()
{
new UserDetailInfo()
{
UserAddress="四川省成都市",
UserCity="成都",
UserCountry="中国",
UserState="当前所在地"
},
new UserDetailInfo()
{
UserAddress="四川省内江市",
UserCity="内江",
UserCountry="中国",
UserState="出生地"
}
}
});
employees.Add
(
new UserInfo
{
UserName = "Json",
UserPwd = "json282",
UserDetailInfomation = new List<UserDetailInfo>()
{
new UserDetailInfo()
{
UserAddress="广东省广州市",
UserCity="广州",
UserCountry="中国",
UserState="当前所在地"
},
new UserDetailInfo()
{
UserAddress="广东省茂名市",
UserCity="茂名",
UserCountry="中国",
UserState="出生地"
}
}
});
employees.Add
(
new UserInfo
{
UserName = "刘敏",
UserPwd = "motorola",
UserDetailInfomation = new List<UserDetailInfo>()
{
new UserDetailInfo()
{
UserAddress="湖南省长沙市",
UserCity="长沙",
UserCountry="中国",
UserState="当前所在地"
},
new UserDetailInfo()
{
UserAddress="湖南省长沙市",
UserCity="长沙",
UserCountry="中国",
UserState="出生地"
}
}
});
return employees;
}
}
/// <summary>
/// 用户详细信息的实体
/// </summary>
public class UserDetailInfo
{
public string UserAddress { get; set; }
public string UserCity { get; set; }
public string UserState { get; set; }
public string UserCountry { get; set; }
}
最后我们来看看它的运行效果,如果需要源码请点击SLDataGridRowDetail.zip下载。
本文来自程兴亮的博客,原文地址:http://www.cnblogs.com/chengxingliang/archive/2011/07/22/2112895.html
在Silverlight中的DataGrid控件使用中我们想点击其中一行并且看这一行的详细信息应该如何做呢?而且这个详细信息是多行的数据,而非简单的几个属性。
在这里我们使用DataGrid.RowDetailsTemplate来设置或者获取行详细信息。首先我们准备一个DataGrid命名为A,设置其RowDetailsVisibilityMode="VisibleWhenSelected" (行详细信息模板的显示模式是当这行被选中的时候展开这行的详细信息。)然后再为A设置DataGrid.RowDetailsTemplate模板,并且在这个模板中添加一个DataGrid命名为B,这就是前台的XAML代码,在后台中我们设置一个实体集AList绑定到A的DataGrid,然后在AList实体集中有一个属性是BList,这个就是多行的详细信息。将BList详细信息字段绑定到B的DataGrid控件的ItemsSource即可。
下面我们来看看这个简单的应用技巧的Xaml代码如下:
<Grid x:Name="LayoutRoot" Background="White">
<!--这里是第一个DataGrid,其DataGrid.RowDetailsTemplate模板会绑定另外一个DataGrid以显示其详细信息-->
<sdk:DataGrid x:Name="gridEmployee" CanUserReorderColumns="False" CanUserSortColumns="False"
RowDetailsVisibilityMode="VisibleWhenSelected"
HorizontalAlignment="Center" ScrollViewer.VerticalScrollBarVisibility="Auto"
Height="200" AutoGenerateColumns="False" Width="422" VerticalAlignment="Center">
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn Width="150"
Header="用户名"
Binding="{Binding UserName}"/>
<sdk:DataGridTextColumn Width="150"
Header="用户密码"
Binding="{Binding UserPwd}"/>
</sdk:DataGrid.Columns>
<sdk:DataGrid.RowDetailsTemplate>
<DataTemplate>
<!--这里是第二个DataGrid显示详细信息-->
<sdk:DataGrid AutoGenerateColumns="False" ItemsSource="{Binding UserDetailInfomation}"
HeadersVisibility="None">
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn Width="100"
Header="地址"
Binding="{Binding UserAddress}"/>
<sdk:DataGridTextColumn Width="100"
Header="城市"
Binding="{Binding UserCity}"/>
<sdk:DataGridTextColumn Width="100"
Header="国籍"
Binding="{Binding UserCountry}"/>
<sdk:DataGridTextColumn Width="100"
Header="类型"
Binding="{Binding UserState}"/>
</sdk:DataGrid.Columns>
</sdk:DataGrid>
</DataTemplate>
</sdk:DataGrid.RowDetailsTemplate>
</sdk:DataGrid>
</Grid>
然后我们来看看他的数据源的Xaml.cs代码如下:
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
this.gridEmployee.ItemsSource = new UserInfo().GetEmployeeData();
}
}
/// <summary>
/// 用户信息
/// </summary>
public class UserInfo
{
public string UserName { get; set; }
public string UserPwd { get; set; }
/// <summary>
/// 用户详细信息
/// </summary>
public List<UserDetailInfo> UserDetailInfomation{get;set;}
public UserInfo()
{ }
/// <summary>
/// 获取用户信息的实例
/// </summary>
/// <returns></returns>
public List<UserInfo> GetEmployeeData()
{
List<UserInfo> employees = new List<UserInfo>();
employees.Add
(
new UserInfo
{
UserName = "李伟",
UserPwd = "1333821",
UserDetailInfomation = new List<UserDetailInfo>()
{
new UserDetailInfo()
{
UserAddress="四川省成都市",
UserCity="成都",
UserCountry="中国",
UserState="当前所在地"
},
new UserDetailInfo()
{
UserAddress="四川省内江市",
UserCity="内江",
UserCountry="中国",
UserState="出生地"
}
}
});
employees.Add
(
new UserInfo
{
UserName = "Json",
UserPwd = "json282",
UserDetailInfomation = new List<UserDetailInfo>()
{
new UserDetailInfo()
{
UserAddress="广东省广州市",
UserCity="广州",
UserCountry="中国",
UserState="当前所在地"
},
new UserDetailInfo()
{
UserAddress="广东省茂名市",
UserCity="茂名",
UserCountry="中国",
UserState="出生地"
}
}
});
employees.Add
(
new UserInfo
{
UserName = "刘敏",
UserPwd = "motorola",
UserDetailInfomation = new List<UserDetailInfo>()
{
new UserDetailInfo()
{
UserAddress="湖南省长沙市",
UserCity="长沙",
UserCountry="中国",
UserState="当前所在地"
},
new UserDetailInfo()
{
UserAddress="湖南省长沙市",
UserCity="长沙",
UserCountry="中国",
UserState="出生地"
}
}
});
return employees;
}
}
/// <summary>
/// 用户详细信息的实体
/// </summary>
public class UserDetailInfo
{
public string UserAddress { get; set; }
public string UserCity { get; set; }
public string UserState { get; set; }
public string UserCountry { get; set; }
}
最后我们来看看它的运行效果,如果需要源码请点击SLDataGridRowDetail.zip下载。
本文来自程兴亮的博客,原文地址:http://www.cnblogs.com/chengxingliang/archive/2011/07/22/2112895.html
相关文章推荐
- Silverlight实用窍门系列:48.DataGrid行详细信息的绑定--DataGrid.RowDetailsTemplate【附带实例源码】
- Silverlight实用窍门系列:48.DataGrid行详细信息的绑定--DataGrid.RowDetailsTemplate
- Silverlight实用示例 - DataGrid行详细信息的绑定DataGrid.RowDetailsTemplate
- 由于内部错误,服务器无法处理该请求。有关该错误的详细信息,请打开服务器上的 IncludeExceptionDetailInFaults (从 ServiceBehaviorAttribute 或从 <serviceDebug> 配置行为)以便将异常信息发送回客户端,
- (源码)SilverLight,分页,数据库取数据,增删改查,显示DataGrid行详细信息.....
- 异常信息:由于内部错误,服务器无法处理该请求。有关该错误的详细信息,请打开服务器上的 IncludeExceptionDetailInFaults
- ASP.net:利用RowFilter属性,将一个DataSet绑定到两个DataGridhttp://www.ninedns.com/asp.net/2007430223347.html
- jquery与DataGrid实现点击列名显示/隐藏详细信息
- 利用RowFilter属性,将一个DataSet绑定到两个DataGrid
- DataGrid 控件中显示和配置行详细信息
- 由于内部错误,服务器无法处理该请求。有关该错误的详细信息,请打开服务器上的 IncludeExceptionDetailInFaults (从 ServiceBehaviorAttribute 或从 <serviceDebug> 配置行为)以便将异常信息发送回客户端,或打开对每个 Microsoft .NET Framework SDK 文档的跟踪并检查服务器跟踪日志。
- WPF中的DataGrid的RowDetail显示问题
- 利用RowFilter属性,将一个DataSet绑定到两个DataGrid
- xen list 输出信息详细说明---转载
- 详细信息页面(detail.jsp)
- easyUI 展开DataGrid里面的行显示详细信息
- easyui-datagrid的detailview扩展动态显示行数据详细内容(C#MVC)
- 利用RowFilter属性,将一个DataSet绑定到两个DataGrid
- Silverlight 通过点击按钮显示/隐藏DataGrid的RowDetail
- easyUI 展开DataGrid里面的行显示详细信息