Windows Develop Bookmark and Share   
 index > Windows Forms Designer > How to add Sort Icon to Data Table(Column) in windows aplication?
 

How to add Sort Icon to Data Table(Column) in windows aplication?

I am creating datatable and addingcolumns dynamically. How to show sort icon in each column when datatable loaded?

thanks in advance..
Ganapatisb  Thursday, September 03, 2009 11:35 AM

Hi,

You can set the Column.HeaderCell.SortGlyphDirection property. For example:

DataTable dt01 = new DataTable();

dt01.Columns.Add("col01");

dt01.Columns.Add("col02");

dt01.Columns.Add("col03");

dt01.Rows.Add("11", "aa","1a");

dt01.Rows.Add("22", "bb","2b");

dataGridView1.DataSource = dt01;

dataGridView1.Columns[0].HeaderCell.SortGlyphDirection = SortOrder.Ascending;

dataGridView1.Columns[1].HeaderCell.SortGlyphDirection = SortOrder.Descending;

DataGridViewColumnHeaderCell.SortGlyphDirection Property

Gets or sets a value indicating which sort glyph is displayed.

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcolumnheadercell.sortglyphdirection.aspx

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Thursday, September 10, 2009 6:53 AM

write code tosortdata of a columnin the datagridviewevent under which you want to sort out the column data.

DataGridView1.Sort(Column1, System.ComponentModel.ListSortDirection.Ascending)




Rohini Chavakula  Friday, September 11, 2009 1:42 PM

Hi,

You can set the Column.HeaderCell.SortGlyphDirection property. For example:

DataTable dt01 = new DataTable();

dt01.Columns.Add("col01");

dt01.Columns.Add("col02");

dt01.Columns.Add("col03");

dt01.Rows.Add("11", "aa","1a");

dt01.Rows.Add("22", "bb","2b");

dataGridView1.DataSource = dt01;

dataGridView1.Columns[0].HeaderCell.SortGlyphDirection = SortOrder.Ascending;

dataGridView1.Columns[1].HeaderCell.SortGlyphDirection = SortOrder.Descending;

DataGridViewColumnHeaderCell.SortGlyphDirection Property

Gets or sets a value indicating which sort glyph is displayed.

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcolumnheadercell.sortglyphdirection.aspx

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Thursday, September 10, 2009 6:53 AM

write code tosortdata of a columnin the datagridviewevent under which you want to sort out the column data.

DataGridView1.Sort(Column1, System.ComponentModel.ListSortDirection.Ascending)




Rohini Chavakula  Friday, September 11, 2009 1:42 PM

You can use google to search for other answers

Custom Search

More Threads

• TypeCodeDomSerializer does not create override function
• c++/cli designer question
• sorting Datagridview
• complex property - serialization
• How to set a DragIcon when a control is dragged and dropped on a designer
• Hosing Form Designer and control property "Enabled" problem
• User Control That Could Contain Controls Dragged On It At Design Time
• Reading appSettings from a custom ControlDesigner
• Call UC load event from main form
• Why is VS 2003 Designer Mode so slow in loading some forms?