• 自定义silverlight中datagrid的排序事件


    <sdk:DataGrid AutoGenerateColumns="False" CanUserSortColumns="False" CanUserReorderColumns="False"  IsReadOnly="True" HorizontalAlignment="Left" Margin="0,0,0,86" x:Name="ErrorCodeGrid" Width="662" Grid.Row="1" MouseLeftButtonDown="ErrorCodeGrid_MouseLeftButtonDown">
        <sdk:DataGrid.Columns>
            <sdk:DataGridTextColumn Header="日期" Binding="{Binding Date}" Width="110"/>
            <sdk:DataGridTextColumn Header="地市" Binding="{Binding Area}" Width="110"/>
            <sdk:DataGridTextColumn Header="发送/接收" Binding="{Binding Pattern}" Width="95" />
            <sdk:DataGridTextColumn Header="短信类型" Binding="{Binding EmailType}" Width="115"/>
            <sdk:DataGridTextColumn Header="机型" Binding="{Binding PhoneType}" Width="115"/>
            <sdk:DataGridTextColumn Header="比例" Binding="{Binding Ratio}" Width="*"/>
        </sdk:DataGrid.Columns>
    </sdk:DataGrid>

    //下面为单机事件

    private void ErrorCodeGrid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        var u = from element in VisualTreeHelper.FindElementsInHostCoordinates(e.GetPosition(null), ErrorCodeGrid)
                where element is DataGridColumnHeader
                select element;
        if (u.Count() == 1)
        {
            //鼠标点击的ColumnHeader
            DataGridColumnHeader header = (DataGridColumnHeader)u.Single();
            //要排序的字段
            string _newSort = header.Content.ToString();
            if (dir == "desc")
            {
                dir = "asc";
            }
            else
            {
                dir = "desc";
            }
            sortFiled = _newSort;
            sortHeader = header;
            SortData(dir, sortFiled);
            e.Handled = true;
        }
        else
        {
            e.Handled = false;
        }
    }

    //排序事件

    void SortData(string sortType, string sortFiled)
    {
        dDetailList = ChangeResult(DetailList);
        if (sortType == "desc")
        {
            switch (sortFiled)
            {
                case "比例":
                    dDetailList = dDetailList.OrderByDescending(u => u.Ratio).ToList();
                    break;
     
                default:
                    break;
            }
        }
        else
        {
            switch (sortFiled)
            {
                case "比例":
                    dDetailList = dDetailList.OrderBy(u => u.Ratio).ToList();
                    break;
                default:
                    break;
            }
        }
        DetailList = ChangeBackResult(dDetailList);
        fenye("first");
    }

    //分页事件

    void fenye(string done)
           {
               TotalCount = DetailList.Count();
               if (TotalCount % PageSize == 0)
               {
                   TotalPage = TotalCount / PageSize;
               }
               else
               {
                   TotalPage = TotalCount / PageSize + 1;
               }

               first.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0));
               pre.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0));
               next.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0));
               last.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0));

               if (done == "first")
               {
                   CurrentPage = 1;
               }
               else if (done == "last")
               {
                   CurrentPage = TotalPage;
                   next.Foreground = new SolidColorBrush(Color.FromArgb(255, 178, 187, 190));
                   last.Foreground = new SolidColorBrush(Color.FromArgb(255, 178, 187, 190));
               }
               else if (done == "pre")
               {
                   if (CurrentPage > 1)
                       CurrentPage -= 1;
                   else
                   {
                       first.Foreground = new SolidColorBrush(Color.FromArgb(255, 178, 187, 190));
                       pre.Foreground = new SolidColorBrush(Color.FromArgb(255, 178, 187, 190));
                   }
               }
               else if (done == "next")
               {
                   if (CurrentPage < TotalPage)
                       CurrentPage += 1;
                   else
                   {
                       next.Foreground = new SolidColorBrush(Color.FromArgb(255, 178, 187, 190));
                       last.Foreground = new SolidColorBrush(Color.FromArgb(255, 178, 187, 190));
                   }
               }

               if (TotalPage == 1)
               {
                   first.Foreground = new SolidColorBrush(Color.FromArgb(255, 178, 187, 190));
                   pre.Foreground = new SolidColorBrush(Color.FromArgb(255, 178, 187, 190));
                   next.Foreground = new SolidColorBrush(Color.FromArgb(255, 178, 187, 190));
                   last.Foreground = new SolidColorBrush(Color.FromArgb(255, 178, 187, 190));
               }

               pageShow.Text = CurrentPage + "/" + TotalPage;
               List<ErrorCodeDetailBind> query = DetailList.Take(CurrentPage * PageSize).Skip((CurrentPage - 1) * PageSize).ToList();
               ErrorCodeGrid.ItemsSource = query;
           }

  • 相关阅读:
    MySQL教程115-MySQL查看触发器
    MySQL教程114-MySQL创建触发器
    MySQL教程113-MySQL流程控制语句
    MySQL教程112-MySQL游标的定义及使用
    MySQL教程111-MySQL定义条件和处理程序
    MySQL教程110-MySQL变量的定义和赋值
    MySQL教程109-MySQL调用存储过程和函数
    MySQL教程108-MySQL存储函数
    mysql 启动关闭流程
    mysql 连接管理工具
  • 原文地址:https://www.cnblogs.com/kurt/p/3678255.html
Copyright © 2020-2023  润新知