Summary of some sorting experience in DevExpress. XtraGrid

Source: Internet
Author: User

1. Specify a column for sorting

Dgvcontent. Columns ["somefieldname"]. sortorder = devexpress. Data. columnsortorder. ascending;

2. For sorted data, do not want it to be sorted or specify another sort

Dgvcontent. clearsorting ();

3. Specify tables to be sorted by special columns only

Code Private void dgvcontent_endsorting (Object sender, system. eventargs e ){
Gridview View
= Sender
As gridview;
String sort = (view. datasource as dataview). Sort;
If (sort! = String. Empty)
(View. datasource as dataview). Sort = "[col1]," + sort;
}

4. When you click the table header for sorting, a dialog box is displayed, asking the user to confirm whether the sorting is performed.

 

Code Private void dgvcontent_mouseup (Object sender, mouseeventargs E)
{
If (e. Button! = MouseButtons. Left | e. Clicks> 1)
Return;

Gridview view = sender as gridview;
If (view. State! = Gridstate. columndown)
Return;


Point P = view. gridcontrol. pointtoclient (mouseposition );

Gridhitinfo info = view. calchitinfo (P );
If (info. hittest = gridhittest. Column)
{

If (MessageBox. Show (string. Format ("Sort by {0} column? ", Info. Column. Caption ),
"Confirmation", MessageBoxButtons. YesNo )! = DialogResult. Yes)
{
(DevExpress. Utils. DXMouseEventArgs) e). Handled = true;
This. begininvoke (New methodinvoker (view. layoutchanged ));

}

}

}

5. display the sorting information in the group header.

 

Code Private void dgvContent_MouseUp (object sender, MouseEventArgs e)
{
If (e. Button! = MouseButtons. Left | e. Clicks> 1) return;
GridView view = sender as GridView;
If (view. State! = GridState. ColumnDown) return;
Point P = view. gridcontrol. pointtoclient (mouseposition );
Gridhitinfo info = view. calchitinfo (P );
If (info. hittest = gridhittest. Column)
{
If (info. Column. sortorder! = Devexpress. Data. columnsortorder. ascending | info. Column. sortindex! = View. sortinfo. Count-1)
{
Info. Column. sortindex = view. sortinfo. count;
Info. Column. sortorder = devexpress. Data. columnsortorder. ascending;
}
Else if (info. Column. sortorder = devexpress. Data. columnsortorder. ascending)
{
Info. Column. sortorder = devexpress. Data. columnsortorder. Descending;
}
If (info. Column. sortorder = devexpress. Data. columnsortorder. ascending)
Dgvcontent. grouppaneltext = "drag a column by" + info. Column. Caption + "ASCENDING ";
If (info. Column. sortorder = devexpress. Data. columnsortorder. Descending)
DgvContent. GroupPanelText = "drag a Column by" + info. Column. Caption + "descending ";
(DevExpress. Utils. DXMouseEventArgs) e). Handled = true;
This. BeginInvoke (new MethodInvoker (view. LayoutChanged ));

}

6. Clear sorting of other columns

 

Code For (int I = 0; I <view. Columns. Count; I ++)
{
If (! View. Columns [I]. Equals (info. Column ))
{
View. Columns [I]. SortOrder = DevExpress. Data. ColumnSortOrder. None;
}
}

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.