473,397 Members | 2,056 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

DataGridView - Can't sort with auto mode

MC
I'm stumped. From what I read on MSDN, the code below should allow
the user to click on the column headers to sort the grid
automatically. Can someone point out why it does not?

Craig

~~~

public partial class Form1 : Form
{
private ArrayList items;

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
dataGridView1.AutoGenerateColumns = false;
dataGridView1.SelectionMode =
DataGridViewSelectionMode.FullRowSelect;

items = new ArrayList();
items.Add(new Item(101, "Hammer"));
items.Add(new Item(102, "Nails"));
items.Add(new Item(103, "Saw"));

DataGridViewTextBoxColumn col;

col = new DataGridViewTextBoxColumn();
col.SortMode = DataGridViewColumnSortMode.Automatic;
col.Name = "ID";
col.DataPropertyName = "ID";
dataGridView1.Columns.Add(col);

col = new DataGridViewTextBoxColumn();
col.SortMode = DataGridViewColumnSortMode.Automatic;
col.Name = "Description";
col.DataPropertyName = "Description";
dataGridView1.Columns.Add(col);

dataGridView1.DataSource = items;
}

}

public class Item
{
private int id;
private string description;

public Item(int id, string description)
{
this.id = id;
this.description = description;
}

public int ID { get { return id; } }
public string Description { get { return description; } }
}

May 18 '06 #1
0 1226

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: milk-jam | last post by:
I'm trying to set my datagridview so that the first row will be left blank and to use it as a filtering filed for the datagridview. Until now I was using 2 datagridview the upper one with a header...
2
by: inpuarg | last post by:
Is it possible that - or is there any workarround for adding a new unbound row to a datagridview at bound mode ? Theese are not working. And i don 't want to add a row to dataset then rebind -...
0
by: inpuarg | last post by:
Is it possible to sort datagridview programmatically in virtualmode ? ..Sort() method isn 't working ?
1
by: sapkal.manish | last post by:
Question : How can I find actual row position of DataTable in DataGridView when DataTable is sorted / My source code like this Private WithEvent dgvInwDet as new DataGridView Private...
4
by: Matt | last post by:
I have been searching all over the web for a way to sort a DataGridView based on the actual text being shown in a ComboBox column as opposed to the underlying value (an ID in this case). Can anyone...
0
by: joey.powell | last post by:
I have a Windows Forms application where I need to be able to drag and then drop onto a datagridview control. I already have the code necessary to make the drag part work. I am having problems,...
11
by: =?Utf-8?B?VmFuZXNzYQ==?= | last post by:
Hi all, How can I display a footer in a DataGridView? Thank you in advance, Vanessa
0
by: Peted | last post by:
Hello, Ive got a datagridview, on a splitcontainer, in a system.windows.forms.usercontrol. The datagrid view by default shows 3 colums of data and fills exactly the size of the user control...
3
by: Andrus | last post by:
I have DataGridView in virtual mode containing 3500 rows. In code below, assigning to RowCount value to 3500 takes 8 seconds. CPU usage goes high at this time. Stepping by F11 into user code shows...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.