• silverlight RadGridView 动态添加数据列


            public void BindFaultGridInfo(IList<HealthStatusApp.Web.Models.FaultMajorModel> list)
            {
                rg_Fault.Columns.Clear();
                var DefferList = list.GroupBy(m => m.BurdenMajor).ToList();
                IList<HealthStatusApp.Web.Models.FaultMajorModel> itemFaultlist = DefferList[0].OrderBy(m => m.TimeStamp).ToList();
                for (int i = 0; i < itemFaultlist.Count; i++)
                {
                    if (i == 0)
                    {
                        Telerik.Windows.Controls.GridViewColumn mColumn = new Telerik.Windows.Controls.GridViewColumn();
                        mColumn.Header = "责任专业";
                        mColumn.HeaderTextAlignment = TextAlignment.Center;
    
                        //动态添加一列数据模板
                        StringBuilder mbTemp = new StringBuilder();
                        mbTemp.Append("<DataTemplate ");
                        mbTemp.Append("xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' ");
                        mbTemp.Append("xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' ");
                        mbTemp.Append("xmlns:d='http://schemas.microsoft.com/expression/blend/2008' ");
                        mbTemp.Append("xmlns:mc='http://schemas.openxmlformats.org/markup-compatibility/2006' ");
                        mbTemp.Append("xmlns:telerik='http://schemas.telerik.com/2008/xaml/presentation' >");
                        mbTemp.Append("<TextBlock Text="{Binding BurdenMajor}"/>");
                        mbTemp.Append("</DataTemplate>");
                        DataTemplate dtmTemplate = (DataTemplate)XamlReader.Load(mbTemp.ToString());
                        mColumn.CellTemplate = dtmTemplate;
                        rg_Fault.Columns.Add(mColumn);
                    }
    
                    Telerik.Windows.Controls.GridViewColumn oColumn = new Telerik.Windows.Controls.GridViewColumn();
                    oColumn.Header = itemFaultlist[i].TimeStamp.ToString("yyyy/MM");
                    oColumn.HeaderTextAlignment = TextAlignment.Center;
                    oColumn.Width = 1000 / itemFaultlist.Count;
                    oColumn.TextAlignment = TextAlignment.Center;
                    oColumn.FooterTextAlignment = TextAlignment.Center;
    
                    //动态添加一列的数据模板
                    StringBuilder sbTemp = new StringBuilder();
                    sbTemp.Append("<DataTemplate ");
                    sbTemp.Append("xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' ");
                    sbTemp.Append("xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' ");
                    sbTemp.Append("xmlns:d='http://schemas.microsoft.com/expression/blend/2008' ");
                    sbTemp.Append("xmlns:mc='http://schemas.openxmlformats.org/markup-compatibility/2006' ");
                    sbTemp.Append("xmlns:telerik='http://schemas.telerik.com/2008/xaml/presentation' >");
                    sbTemp.Append("<TextBlock Text="{Binding FaultCount}"/>");
                    sbTemp.Append("</DataTemplate>");
                    DataTemplate dtTemplate = (DataTemplate)XamlReader.Load(sbTemp.ToString());
                    oColumn.CellTemplate = dtTemplate;
                    rg_Fault.Columns.Add(oColumn);
                }
                rg_Fault.ItemsSource = list.Take(DefferList.Count);
            }
    View Code
  • 相关阅读:
    BZOJ-1497 最大获利
    POJ-3680 Intervals & NOI 2008 志愿者招募 费用流
    CodeForces 663E Binary Table
    南昌区域赛-G Eating Plan
    HDU-5909 Tree Cutting
    BZOJ-4589 Hard Nim
    UVA-12633 Super Rooks on Chessboard
    SPOJ-TSUM Triple Sums
    HDU-4609 3-idiots
    Kattis-aplusb A+B problem
  • 原文地址:https://www.cnblogs.com/yisheng/p/3642235.html
Copyright © 2020-2023  润新知