The GridView Sorting Problem in DevGridControl,

Source: Internet
Author: User

The GridView Sorting Problem in DevGridControl,

Because ** and other content need to be displayed in the data source, the data column is of the string type. The result is as follows:

At this time, we need to do some processing to achieve the desired sorting effect, first set the attribute
gridColumn1.SortMode = DevExpress.XtraGrid.ColumnSortMode.Custom;

Then implement it in the CustomColumnSort event

        void gdv_CustomColumnSort(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnSortEventArgs e)        {            if (e.Column != null)            {                string value1 = e.Value1.ToString();                string value2 = e.Value2.ToString();                int result = Comparer.Default.Compare                    (ConvertToDecimal(value1, e.SortOrder), ConvertToDecimal(value2, e.SortOrder));                e.Result = result;                e.Handled = true;            }        }        private decimal ConvertToDecimal(string input, DevExpress.Data.ColumnSortOrder sortOrder)        {            decimal result = 0;            if (string.IsNullOrWhiteSpace(input) || input.Equals("**") || input.Equals("--"))                result = sortOrder == DevExpress.Data.ColumnSortOrder.Ascending ? 9999 : -9999;            else                decimal.TryParse(input, out result);            return result;        }
The effect is as follows:
Then, another problem occurs: an image is displayed for a column based on the int type value, but the image is not sorted by the int type value. The solution is to set SortMode for this column.
gridColumn1.SortMode = DevExpress.XtraGrid.ColumnSortMode.Value;

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.