当前位置:  开发笔记 > 编程语言 > 正文

通过单击Compact Framework中的列标题对DataGrid进行排序?

如何解决《通过单击CompactFramework中的列标题对DataGrid进行排序?》经验,为你挑选了1个好方法。

这在.Net Compact Framework中是否可行?与Desktop Framework相比,它有各种各样的东西.

我想知道Compact Framework是否在我们的移动应用程序中使用此功能请求占了上风.



1> user1054922..:

由于该网站不再可用,以下是内容:

    public static void SortDataGrid(object sender, MouseEventArgs e)
    {
        DataGrid.HitTestInfo hitTest;
        DataTable dataTable;
        DataView dataView;
        string columnName;
        DataGrid dataGrid;

        // Use only left mouse button clicks
        if (e.Button == MouseButtons.Left)
        {
            // Set dataGrid equal to the object that called this event handler
            dataGrid = (DataGrid)sender;

            // Perform a hit test to determine where the mousedown event occurred
            hitTest = dataGrid.HitTest(e.X, e.Y);

            // If the MouseDown event occurred on a column header,
            // then perform the sorting operation.
            if (hitTest.Type == DataGrid.HitTestType.ColumnHeader)
            {
                // Get the DataTable associated with this DataGrid.
                dataTable = (DataTable)dataGrid.DataSource;

                // Get the DataView associated with the DataTable.
                dataView = dataTable.DefaultView;

                // Get the name of the column that was clicked.
                if (dataGrid.TableStyles.Count != 0)
                    columnName = dataGrid.TableStyles[0].GridColumnStyles[hitTest.Column].MappingName;
                else
                    columnName = dataTable.Columns[hitTest.Column].ColumnName;

                // If the sort property of the DataView is already the current
                // column name, sort that column in descending order.
                // Otherwise, sort on the column name.
                if (dataView.Sort == columnName)
                    dataView.Sort = columnName + " DESC";
                else
                    dataView.Sort = columnName;
            }
        }
    }

推荐阅读
kikokikolove
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有