I couldn't find a sample of paging for UltraWinGrid, so I've written one.
This sample simulate paging on client side only, meaning, all data is loaded on startup & displayed in pages.
The sample supports an UltraWinGrid that feeds from MS BindingSource. It also supports DataSource changes (Add\delete\update).
using
{
InitializeComponent();dataGrid =
InitializeComponent();
dataGrid.InitializeRow +=
dataGrid.DataSource = bindingSource;
dataSource.Add(i);
}
dataGrid.DataSource = dataSource;
btnFirstPage.Click +=
btnPreviousPage.Click +=
btnNextPage =
btnLastPage =
btnFirstPage, btnPreviousPage, lblPageNumber, btnNextPage, btnLastPage});
pagingToolbar.Dock =
pagingToolbar.LayoutStyle =
RefreshGrid();
RefreshButtons();
e.Row.Index > (PAGE_SIZE * _currentPage) - 1)
dataGrid.Rows.All.Length > 0)
_currentPage = lastPages;
_currentPage = 1;
_currentPage--;
_currentPage++;
btnPreviousPage.Enabled = _currentPage > 1;
btnFirstPage.Enabled = btnPreviousPage.Enabled;
btnNextPage.Enabled = lastRow.Index > (PAGE_SIZE * _currentPage) - 1;
btnLastPage.Enabled = btnNextPage.Enabled;
Hi,Its great to know this peice of code enables sorting for Ultrawingrid but there are some issues with the codecoz of which i couldnt run it properly.
I am getting following errors.
Error 1 'System.Array' does not contain a definition for 'Last' at _currentPage = (((UltraGridRow)dataGrid.Rows.All.Last()).Index / PAGE_SIZE) + 1;
and another errorError 1 Cannot implicitly convert type 'System.Windows.Forms.ToolStripButton' to 'int' atpagingToolbar = new ToolStrip(new ToolStripItem[btnFirstPage, btnPreviousPage, lblPageNumber, btnNextPage, btnLastPage]);
Thanks in advance,Damu
First error can be fixed easily by adding a using statement to System.Linq. This namespace contains the definition of the Last() extention method.
The second error is just a syntax problem. This is the correct syntax:
pagingToolbar = new ToolStrip(new ToolStripItem[] { btnFirstPage, btnPreviousPage, lblPageNumber, btnNextPage, btnLastPage});
Thanks, i was actually busy with some production issue yday and was very confused, couldnt figure out simple stuff. It is really great to provide paging support which the ultragrid doesnt support by itself. Great work from you.
Thanks for the quick reply.
This was a really useful thread... I have a small efficiency improvement to tack on:
List<int> showrows = new List<int>(PAGE_SIZE); private void RefreshGrid() { try { foreach (int x in showrows) { dataGrid.Rows[x].Hidden = true; } } catch { } showrows.Clear(); try { for (int x = (PAGE_SIZE * (_currentPage - 1)); x < (PAGE_SIZE * (_currentPage - 1)) + PAGE_SIZE; x++) { showrows.Add(x); dataGrid.Rows[x].Hidden = false; } } catch { } }
Also, have it hide all of the rows right after setting the data source. That kills the minor lag and CPU spike in the original if you have a large data set.
Good work on the initial implementation. It's too bad that functionality isn't already built in to the grids.