seagull
seagull

Reputation:

c# datagridview datatable

hi i have a datagridview in a form... users by clicking the column name can sort the row data in that column either in ascending or descending orders... how is it possible to disable it? so that the data in rows of every columns stays in that order in which they were on the start of the form... thanks!

Upvotes: 2

Views: 1439

Answers (4)

PositiveGuy
PositiveGuy

Reputation: 47733

use a repeater and custom pager control. Forget GridView, DataGrid, etc.

Upvotes: 0

Henk Holterman
Henk Holterman

Reputation: 273179

Like the other answers state, there is no global property on the DataGrid, you will have to set on each column individually.

for(int x = 0; x < dataGridView1.Columns/Count; x++)
  dataGridView1.Columns[x].SortMode = DataGridViewColumnSortMode.NotSortable;

Upvotes: 2

Jay Riggs
Jay Riggs

Reputation: 53595

Programmatically:

YourDataColumn.SortMode = DataGridViewColumnSortMode.NotSortable;

In the designer:

  1. Right click your DGV and select 'Edit Columns...' from the popup menu. The 'Edit Columns' dialog appears.
  2. In the 'Edit Columns' dialog, update the SortMode property to 'NotSortable' for the column(s) you want to disable sorting on.

Upvotes: 7

ddc0660
ddc0660

Reputation: 4052

Set the SortMode on the column to Programmatic.

Reference is in VB, but should work in C#.

Upvotes: 0

Related Questions