GrapeCity MultiRow Windows Forms Documentation
Sorting Rows using Column Headers

You can use the column header cell or the commands in the header drop-down list to sort rows.

Column Header Dropdown

  • Sorting cannot be used with virtual mode.
  • New rows are not considered while sorting.

Clicking Column Headers

To enable sorting when clicking on the column header, set the ColumnHeaderCell.SortMode property to Automatic. Since this prevents selecting cells using the column headers, also set the ColumnHeaderCell.SelectionMode property (HeaderCell.SelectionMode property) to None.

Using Code

This example enables sorting.

[VB]

Imports GrapeCity.Win.MultiRow

Dim template As Template = template.Default

Dim columnHeaderCell As ColumnHeaderCell = DirectCast(template.ColumnHeaders(0).Cells(0), ColumnHeaderCell)
columnHeaderCell.SelectionMode = MultiRowSelectionMode.None
columnHeaderCell.SortMode = SortMode.Automatic
columnHeaderCell.Value = "(Click)"

GcMultiRow1.Template = template
GcMultiRow1.AllowUserToAddRows = False

' Input sample data 
GcMultiRow1.RowCount = 3
GcMultiRow1.Rows(0)("textBoxCell1").Value = 2
GcMultiRow1.Rows(1)("textBoxCell1").Value = 1
GcMultiRow1.Rows(2)("textBoxCell1").Value = 3

[CS]

using GrapeCity.Win.MultiRow;

Template template = Template.Default; 

ColumnHeaderCell columnHeaderCell = (ColumnHeaderCell)template.ColumnHeaders[0].Cells[0];
columnHeaderCell.SelectionMode = MultiRowSelectionMode.None;
columnHeaderCell.SortMode = SortMode.Automatic;
columnHeaderCell.Value = "(Click)";

gcMultiRow1.Template = template; 
gcMultiRow1.AllowUserToAddRows = false; 

// Input sample data 
gcMultiRow1.RowCount = 3; 
gcMultiRow1.Rows[0]["textBoxCell1"].Value = 2; 
gcMultiRow1.Rows[1]["textBoxCell1"].Value = 1; 
gcMultiRow1.Rows[2]["textBoxCell1"].Value = 3;

When sorting using column headers, the sort state is displayed on the column header as "Sort Glyph." You can get or set the state of the sort glyph using the ColumnHeaderCell.SortGlyphDirection property. When you set the ColumnHeaderCell.SortMode property to Automatic, the sort direction becomes fixed in the ascending or descending order. To implement custom sorting, set the ColumnHeaderCell.SortMode property to Programmatic and use the SortCompare event.

Setting the Drop-down list

In order to implement sorting using the drop-down list, set the instance of the HeaderDropDownList class into the ColumnHeaderCell.DropDownList property. Additionally, in order to enable the sorting commands, set the third argument of the constructor to True.

Using Code

This example implements sorting using the drop-down list.

[VB]

Imports GrapeCity.Win.MultiRow

Dim template As Template = Template.Default

Dim columnHeaderCell As ColumnHeaderCell = DirectCast(template.ColumnHeaders(0).Cells(0), ColumnHeaderCell)
columnHeaderCell.DropDownList = New HeaderDropDownList("textBoxCell1", False, True)

GcMultiRow1.Template = template
GcMultiRow1.AllowUserToAddRows = False

' Input Sample data
GcMultiRow1.RowCount = 3
GcMultiRow1.Rows(0)("textBoxCell1").Value = 2
GcMultiRow1.Rows(1)("textBoxCell1").Value = 1
GcMultiRow1.Rows(2)("textBoxCell1").Value = 3

[CS]

using GrapeCity.Win.MultiRow;

Template template = Template.Default;

ColumnHeaderCell columnHeaderCell = (ColumnHeaderCell)template.ColumnHeaders[0].Cells[0];
columnHeaderCell.DropDownList = new HeaderDropDownList("textBoxCell1", false, true);

gcMultiRow1.Template = template;
gcMultiRow1.AllowUserToAddRows = false;

// Input Sample data
gcMultiRow1.RowCount = 3;
gcMultiRow1.Rows[0]["textBoxCell1"].Value = 2;
gcMultiRow1.Rows[1]["textBoxCell1"].Value = 1;
gcMultiRow1.Rows[2]["textBoxCell1"].Value = 3;

The range of rows to be sorted can be set with the HeaderDropDownList.StartRow and the HeaderDropDownList.EndRow properties.

Sort Indicator

You can set the indicator image during sorting using the ColumnHeaderCell.SortGlyphAscendingImage and ColumnHeaderCell.SortGlyphDescendingImage properties.

The Sort indicator does not support zoom.

Using Code

The following code sets an indicator image which is displayed when sorting is executed.

[VB]

Imports GrapeCity.Win.MultiRow

Dim template As Template = template.Default

Dim columnHeaderCell As ColumnHeaderCell = DirectCast(template.ColumnHeaders(0).Cells(0), ColumnHeaderCell)
columnHeaderCell.SelectionMode = MultiRowSelectionMode.None
columnHeaderCell.SortMode = SortMode.Automatic
columnHeaderCell.Value = "(クリック)"
columnHeaderCell.SortGlyphAscendingImage = New Bitmap("test1.bmp")
columnHeaderCell.SortGlyphDescendingImage = New Bitmap("test2.bmp")

GcMultiRow1.Template = template
GcMultiRow1.AllowUserToAddRows = False

' Input Sample data 
GcMultiRow1.RowCount = 3
GcMultiRow1.Rows(0)("textBoxCell1").Value = 2
GcMultiRow1.Rows(1)("textBoxCell1").Value = 1
GcMultiRow1.Rows(2)("textBoxCell1").Value = 3

 

[CS]

using GrapeCity.Win.MultiRow;

Template template = Template.Default;

ColumnHeaderCell columnHeaderCell = (ColumnHeaderCell)template.ColumnHeaders[0].Cells[0];
columnHeaderCell.SelectionMode = MultiRowSelectionMode.None;
columnHeaderCell.SortMode = SortMode.Automatic;
columnHeaderCell.Value = "(クリック)";
columnHeaderCell.SortGlyphAscendingImage = new Bitmap("test1.bmp");
columnHeaderCell.SortGlyphDescendingImage = new Bitmap("test2.bmp");

gcMultiRow1.Template = template;
gcMultiRow1.AllowUserToAddRows = false;

// Input sample data   
gcMultiRow1.RowCount = 3;
gcMultiRow1.Rows[0]["textBoxCell1"].Value = 2;
gcMultiRow1.Rows[1]["textBoxCell1"].Value = 1;
gcMultiRow1.Rows[2]["textBoxCell1"].Value = 3;
See Also

 

 


Copyright © GrapeCity, inc. All rights reserved.

Support Options