电商直播系统源码,利用DatagridView BindingNavigato实现分页
2021/9/24 14:40:41
本文主要是介绍电商直播系统源码,利用DatagridView BindingNavigato实现分页,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
电商直播系统源码,利用DatagridView BindingNavigato实现分页的相关代码
List<person> personlist =new List<person>(); int pageSize = 20; int pageCount = 0; private void Form1_Load(object sender, EventArgs e) { for (int i = 0; i < 112; i++) { person p = new person(); p.name = "test" + i.ToString(); p.age = i; personlist.Add(p); } LoadData(1, dgvDemo); bindingNavigatorPositionItem.Enabled = true; // Set the status of the BindingNavigator control if (pageCount == 0 || pageCount == 1) { bindngrDemo.MoveFirstItem.Enabled = false; bindngrDemo.MoveLastItem.Enabled = false; bindngrDemo.MoveNextItem.Enabled = false; bindngrDemo.MovePreviousItem.Enabled = false; } else { bindngrDemo.MoveFirstItem.Enabled = false; bindngrDemo.MoveLastItem.Enabled = true; bindngrDemo.MoveNextItem.Enabled = true; bindngrDemo.MovePreviousItem.Enabled = false; bindngrDemo.PositionItem.Text = "1"; bindngrDemo.CountItem.Text = "of {" + pageCount.ToString() + "}"; } } private void LoadData(int pageIndex, DataGridView dgvDemo) { int Count = personlist.Count(); if (Count % pageSize == 0) pageCount = Count / pageSize; else pageCount = Count / pageSize + 1; List<person> plist = personlist.Skip((pageIndex-1) * pageSize).Take(pageSize).ToList(); BindingSource bindseDemo = new BindingSource(); bindseDemo.DataSource = plist; dgvDemo.DataSource = bindseDemo; } private void bindingNavigatorMoveFirstItem_Click(object sender, EventArgs e) { LoadData(1, dgvDemo); bindngrDemo.PositionItem.Text = "1"; bindngrDemo.MoveFirstItem.Enabled = false; bindngrDemo.MovePreviousItem.Enabled = false; bindngrDemo.MoveNextItem.Enabled = true; bindngrDemo.MoveLastItem.Enabled = true; } private void bindingNavigatorMovePreviousItem_Click(object sender, EventArgs e) { int currentPage = Convert.ToInt32(bindngrDemo.PositionItem.Text); if (currentPage >= 2) { int page = currentPage - 1; bindngrDemo.PositionItem.Text = page.ToString(); LoadData(page, dgvDemo); if (page == 1) { bindngrDemo.MovePreviousItem.Enabled = false; bindngrDemo.MoveFirstItem.Enabled = false; } if (page <= pageCount) { bindngrDemo.MoveNextItem.Enabled = true; bindngrDemo.MoveLastItem.Enabled = true; } } else { MessageBox.Show("This is the first page", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } } private void bindingNavigatorMoveNextItem_Click(object sender, EventArgs e) { int currentPage = Convert.ToInt32(bindngrDemo.PositionItem.Text); if (currentPage < pageCount) { int page = currentPage + 1; bindngrDemo.PositionItem.Text = page.ToString(); LoadData(page, dgvDemo); if (page == pageCount) { bindngrDemo.MoveNextItem.Enabled = false; bindngrDemo.MoveLastItem.Enabled = false; } if (page >= 2) { bindngrDemo.MovePreviousItem.Enabled = true; bindngrDemo.MoveFirstItem.Enabled = true; } } else { MessageBox.Show("This is the last page", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } } private void bindingNavigatorMoveLastItem_Click(object sender, EventArgs e) { LoadData(pageCount, dgvDemo); bindngrDemo.PositionItem.Text = pageCount.ToString(); bindngrDemo.MoveLastItem.Enabled = false; bindngrDemo.MoveNextItem.Enabled = false; bindngrDemo.MovePreviousItem.Enabled = true; bindngrDemo.MoveFirstItem.Enabled = true; } private void bindingNavigatorPositionItem_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar >= 48 && e.KeyChar <= 57) || e.KeyChar == 8 || e.KeyChar == 13 || e.KeyChar == 127) { e.Handled = false; if (e.KeyChar == 13) { int page=Convert.ToInt16(bindingNavigatorPositionItem.Text); LoadData(page, dgvDemo); } } else { e.Handled = true; } } } public class person { public string name { get; set; } public int age { get; set; } }
以上就是 电商直播系统源码,利用DatagridView BindingNavigato实现分页的相关代码,更多内容欢迎关注之后的文章
这篇关于电商直播系统源码,利用DatagridView BindingNavigato实现分页的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-24内网穿透资料入门教程
- 2024-12-24微服务资料入门指南
- 2024-12-24微信支付系统资料入门教程
- 2024-12-24微信支付资料详解:新手入门指南
- 2024-12-24Hbase资料:新手入门教程
- 2024-12-24Java部署资料
- 2024-12-24Java订单系统资料:新手入门教程
- 2024-12-24Java分布式资料入门教程
- 2024-12-24Java监控系统资料详解与入门教程
- 2024-12-24Java就业项目资料:新手入门必备教程