Hello,
I am trying to show a busy cursor icon whilst programmatically sorting my datagridview for a column.
As I have a lot of data, it can take 10 seconds to sort, and I would like to show a busy cursor for this duration.
I can show the busy cursor icon when the user clicks on the column header cell (event).
However, I cant find a suitable event on which to return to the normal cursor.
Any ideas?
Thanks
Loading

Manikavelu VelayuthamRank #413 · 6K reputationPosted Dec 13, 2010, 12:57 AM EST
Sample ASPX code
solara23 reputationPosted Dec 13, 2010, 12:59 AM EST
Manikavelu VelayuthamRank #413 · 6K reputationPosted Dec 13, 2010, 1:00 AM EST
solara23 reputationPosted Dec 13, 2010, 1:03 AM EST
Manikavelu VelayuthamRank #413 · 6K reputationPosted Dec 13, 2010, 1:05 AM EST
Cursor.Current = Cursors.WaitCursor;
try
{
Thread.Sleep(5000);
}
finally
{
Cursor.Current = Cursors.Default;
}
solara23 reputationPosted Dec 13, 2010, 1:08 AM EST
As I get an event for each row comparison, to do the custom sorting.
Like I said, I cant find a suitable event on which to switch back to the default cursor, after the sorting has completed.
Manikavelu VelayuthamRank #413 · 6K reputationPosted Dec 13, 2010, 1:14 AM EST
solara23 reputationPosted Dec 13, 2010, 1:23 AM EST
solara23 reputationPosted Dec 13, 2010, 10:42 AM EST
I had to change the column properties for the DGV to be Programmatic rather than Automatic.
It means you have to manually change the glyphs and invoke the sort manually from the column header click event.
I can still also use my existing SortCompare method.
eg to sort by column 2.....
private void dgdTrades_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
this.Cursor = Cursors.WaitCursor;
dgdTrades.Sort(dgdTrades.Columns[2], ListSortDirection.Ascending);
dgdTrades.Columns[2].HeaderCell.SortGlyphDirection = SortOrder.Ascending;
this.Cursor = Cursors.Default;
}
Manikavelu VelayuthamRank #413 · 6K reputationPosted Dec 13, 2010, 7:20 PM EST
solara23 reputationPosted Dec 15, 2010, 12:10 PM EST
private void dgdTrades_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
statusLabel.Text = "Sorting...";
this.Cursor = Cursors.WaitCursor;
for (int i = 0; i < dgdTrades.ColumnCount; i++)
{
if (e.ColumnIndex==i) {
if (dgdTrades.Columns[e.ColumnIndex].HeaderCell.SortGlyphDirection != SortOrder.Ascending) {
dgdTrades.Sort(dgdTrades.Columns[e.ColumnIndex], ListSortDirection.Ascending);
dgdTrades.Columns[e.ColumnIndex].HeaderCell.SortGlyphDirection = SortOrder.Ascending;
}
else {
dgdTrades.Sort(dgdTrades.Columns[e.ColumnIndex], ListSortDirection.Descending);
dgdTrades.Columns[e.ColumnIndex].HeaderCell.SortGlyphDirection = SortOrder.Descending;
}
}
else {
dgdTrades.Columns[i].HeaderCell.SortGlyphDirection = SortOrder.None;
}
}
statusLabel.Text = "";
this.Cursor = Cursors.Default;
}