RadControls for Silverlight(学习1-GridView) (转载)
2012-02-24 16:46
501 查看
引用:Telerik(官 网:http://www.telerik.com/)是保加利亚的一个软件公司,专注于微软.Net平台的表示层与内容管理控件。我们提供高度稳定性和丰富性能的组件产品,并可应用在非常严格的环境中。现在拥有 Microsoft, HP, Alcoa, BP, Harper Collins, Siemens, T-Mobile, HJ Heinz和一些最主要的教育机构和很多政府机关等客户。
我在使用的版本是RadControls_for_Silverlight4_2011_1_0316,开发工具采用VS2010 +SQLServer2008R2进行测试学习
Grid是我们做系统必不可少的控件了,所以我准备从这个开始,为自己留下学习痕迹。
先是了解控件属性便于下一步学习,常用属性
RadGridView
GridViewDataColumn
GridViewDataColumn.FilteringControl :可自定义表头查询控件
1、产生自动编号-Row Number
· 自定义列与绑定列并存
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
2、行、列、单元格只读设置
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
3、设置网格线颜色
4、保存用户对网格的设置
DEMO中saveandload settings中的Radgridviewsetting.cs非常用用:)
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
本文来自forrestsun 的博客,原文地址:http://www.cnblogs.com/forrestsun/archive/2011/05/13/2045859.html
我在使用的版本是RadControls_for_Silverlight4_2011_1_0316,开发工具采用VS2010 +SQLServer2008R2进行测试学习
Grid是我们做系统必不可少的控件了,所以我准备从这个开始,为自己留下学习痕迹。
先是了解控件属性便于下一步学习,常用属性
RadGridView
常用属性 | 说明 | DEMO名称 |
AutoGenerateColumns="False" | 是否自动产生列 | |
IsReadOnly="True" IsReadOnly="{Binding IsChecked, Mode=TwoWay, ElementName=IsReadOnlyCheckBox}" | 是否只读 | Click Event command |
ShowGroupPanel="False" | 是否显示分组面板(常用,一般情况下是不会用到这个的) | |
DataLoadMode="Asynchronous" | 数据加载模式 | |
RowIndicatorVisibility="Collapsed" | 行指示 | |
SelectionMode="Extended" | Command | |
CanUserDeleteRows="{Binding IsChecked, Mode=TwoWay, ElementName=CanUserDeleteRowsCheckBox}" | 是否可删除行 | Command |
ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" | 横向竖向滚动条设定 | |
IsFilteringAllowed="False" | 列过滤查询是否可用 | Enable/Disable |
ShowColumnFooters="True" | 是否显示列脚 | Totals |
ShowGroupFooters="True" | 是否显示分组列脚 | Totals |
GridLinesVisibility= Both Horizontal Vertical | 网络线设置 | gridlinevisiblity |
属性 | 说明 | DEMO名称 |
IsGroupable="False" | 列是否加入分组 | |
IsFilterable="False" | 列是否可过滤查询 | |
IsSortable="False" | 列是否可排序 | |
DataFormatString="{}{0:c2}" DataFormatString="{}{0:d}" | 列输入格式 |
1、产生自动编号-Row Number
· 自定义列与绑定列并存
XAML <Grid> <telerik:RadGridView x:Name="RadGridView1" ItemsSource="{Binding Customers}" AutoGeneratingColumn="RadGridView1_AutoGeneratingColumn"> <telerik:RadGridView.Columns> <custom:MyColumn Header="#" Width="50" /> </telerik:RadGridView.Columns> </telerik:RadGridView> </Grid>
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
· 自动绑定后的列取消功能(如果取消的列较多,还是需要考虑用别的方法替代)
private void RadGridView1_AutoGeneratingColumn(object sender, Telerik.Windows.Controls.GridViewAutoGeneratingColumnEventArgs e) { if (e.Column.UniqueName == "Order" || e.Column.UniqueName == "Product") { e.Cancel = true; } } · 自定义列的处理 public class MyColumn : Telerik.Windows.Controls.GridViewColumn { public override FrameworkElement CreateCellElement (Telerik.Windows.Controls.GridView.GridViewCell cell, object dataItem) { TextBlock textBlock = cell.Content as TextBlock; if (textBlock == null) { textBlock = new TextBlock(); } textBlock.Text = (this.DataControl.Items.IndexOf(dataItem) + 1).ToString(); return textBlock; } }
2、行、列、单元格只读设置
private void ChangeEnableStateColumn(bool isEnabled) { GridViewHeaderRow headerRow = RadGridView1.ChildrenOfType <GridViewHeaderRow>().FirstOrDefault(); if (headerRow != null) { GridViewCellBase cell = (from c in headerRow.Cells where c.Column.UniqueName == "EmployeeID" select c).FirstOrDefault(); if (cell != null) { cell.IsEnabled = isEnabled; } } foreach (object item in RadGridView1.Items) { GridViewRow row = RadGridView1.ItemContainerGenerator.ContainerFromItem(item) as GridViewRow; if (row != null) { GridViewCellBase cell = (from c in row.Cells where c.Column.UniqueName == "EmployeeID" select c).FirstOrDefault(); if (cell != null) { cell.IsEnabled = isEnabled; } } } } private void ChangeEnableStateCell(bool isEnabled) { if (RadGridView1.Items.Count > 0) { GridViewRow row = RadGridView1.ItemContainerGenerator.ContainerFromItem (RadGridView1.Items[0]) as GridViewRow; if (row != null) { GridViewCellBase cell = (from c in row.Cells where c.Column.UniqueName == "EmployeeID" select c).FirstOrDefault(); if (cell != null) { cell.IsEnabled = isEnabled; } } } } private void ChangeEnableStateRow(bool isEnabled) { if (RadGridView1.Items.Count > 0) { GridViewRow row = RadGridView1.ItemContainerGenerator.ContainerFromItem (RadGridView1.Items[0]) as GridViewRow; if (row != null) { row.IsEnabled = isEnabled; } } }
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
XAML <Grid> <telerik:RadGridView x:Name="RadGridView1" ItemsSource="{Binding Customers}" AutoGeneratingColumn="RadGridView1_AutoGeneratingColumn"> <telerik:RadGridView.Columns> <custom:MyColumn Header="#" Width="50" /> </telerik:RadGridView.Columns> </telerik:RadGridView> </Grid>
3、设置网格线颜色
private void VerticalGridLinesColorPicker_SelectedColorChanged(object sender, EventArgs e) { RadGridView1.VerticalGridLinesBrush = new SolidColorBrush (VerticalGridLinesColorPicker.SelectedColor); } private void HorizontalGridLinesColorPicker_SelectedColorChanged(object sender, EventArgs e) { RadGridView1.HorizontalGridLinesBrush = new SolidColorBrush (HorizontalGridLinesColorPicker.SelectedColor); }
4、保存用户对网格的设置
DEMO中saveandload settings中的Radgridviewsetting.cs非常用用:)
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
本文来自forrestsun 的博客,原文地址:http://www.cnblogs.com/forrestsun/archive/2011/05/13/2045859.html
相关文章推荐
- 【转】RadControls for Silverlight(学习1-GridView)
- (转)RadControls+for+Silverlight(学习1-GridView)
- RadControls for Silverlight(学习1-GridView)
- RadControls for Silverlight(学习1-RadGridView)
- RadControls for Silverlight(学习2-RadDataPager)
- 【转】RadControls for Silverlight(学习2-RadDataPager)
- Silverlight:telerik RadControls中RadGridView的一个Bug及解决办法(转载)
- silverlight:telerik RadControls for Silverlight 主题使用心得
- silverlight RadGridView总结三(转载)
- silverlight:telerik RadControls中RadGridView的一个Bug及解决办法
- silverlight RadGridView总结二(转载)
- silverlight RadGridView总结系列(转载)
- Telerik RadControls for Silverlight 4
- RadControls for Silverlight发布测试版
- RadControls for Silverlight 导出excel
- Telerik RadControls for Silverlight Q3 2008可用,要是有20081117就更好了,有DATAGRID用
- 使用RadControls for Silverlight 2009时报无法找到System.Web.Ria
- Silverlight:telerik RadControls for Silverlight 主题使用心得
- ArcGIS API for Silverlight 入门学习笔记(三):基础地图实例
- Client-side HTML controls for Silverlight 2