DataGridViewPagination
This creates pagination functionality for WinForm's DataGridView
Install / Use
/learn @tgfischer/DataGridViewPaginationREADME
DataGridView Pagination
This creates pagination functionality for WinForm's DataGridView. It allows you to move through the pages by Button controls.
The first step is to add a DataGridView control to your form like how you normally would. Then, set up the DataGridViewPaginationAdapter in your form. In my example form, I do this in the constructor
// Sets up an adapter with a DataTable
this.adapter = new DataGridViewPaginationAdapter(dataTable);
// Event when the page changes
this.adapter.PageChanged += new PageChangedEventHandler(this.adapter_PageChanged);
// Move to the first page
this.adapter.MoveFirst();
Then you have to set up the PageChanged event method.
private void adapter_PageChanged(object sender, PageChangedEventArgs e)
{
// DataTable to hold all of this page's data
DataTable dataTable = this.adapter.GetPage(this.adapter.CurrentPage);
// Display the data in the DataGridView
this.dataGridView.DataSource = dataTable.AsDataView();
bool hasNext = this.adapter.HasNext; // Check for a proceeding page
bool hasPrev = this.adapter.HasPrevious; // Check for a preceding page
// Enable/disable the buttons depending on the page number
this.nextButton.Enabled = hasNext;
this.lastButton.Enabled = hasNext;
this.previousButton.Enabled = hasPrev;
this.firstButton.Enabled = hasPrev;
}
You can then use the DataGridViewPaginationAdapter to move to another page, like so
private void lastButton_Click(object sender, EventArgs e)
{
this.adapter.MoveLast(); // Move to the last page
}
private void nextButton_Click(object sender, EventArgs e)
{
this.adapter.MoveNext(); // Move to the next page
}
private void previousButton_Click(object sender, EventArgs e)
{
this.adapter.MovePrevious(); // Move to the previous page
}
private void firstButton_Click(object sender, EventArgs e)
{
this.adapter.MoveFirst(); // Move to the first page
}
I have also included an example of an editable TextBox that shows what page the user is on. This can be used to jump to another page. I have also shown how to add a Label that displays the total number of pages in the DataGridView
Related Skills
node-connect
351.4kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
110.7kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
351.4kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
351.4kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
