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
solaraPosted Dec 15, 2010, 5:10 PM
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;
}
Manikavelu VelayuthamPosted Dec 14, 2010, 12:20 AM
solaraPosted Dec 13, 2010, 3:42 PM
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;
}
solaraPosted Dec 13, 2010, 6:23 AM
Manikavelu VelayuthamPosted Dec 13, 2010, 6:14 AM
solaraPosted Dec 13, 2010, 6:08 AM
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 VelayuthamPosted Dec 13, 2010, 6:05 AM
Cursor.Current = Cursors.WaitCursor;
try
{
Thread.Sleep(5000);
}
finally
{
Cursor.Current = Cursors.Default;
}
solaraPosted Dec 13, 2010, 6:03 AM
Manikavelu VelayuthamPosted Dec 13, 2010, 6:00 AM
solaraPosted Dec 13, 2010, 5:59 AM
Manikavelu VelayuthamPosted Dec 13, 2010, 5:57 AM
Sample ASPX code