Winform ListView分页控件从其他地方查询获取数据

效果图

通过Pan里边的查询条件 listview和分页控件从中获取数据

自定义

private int Tnum = 0;//总页数
private int Cnum = 0;//当前页数

点击查询按钮

代码变动

Cnum = 1;
txtCurrentPage.Text = Cnum.ToString();

var data = sqlDb.ExecuteReader(sql);
if (data != null)
Tnum = data.Rows.Count % 100 == 0 ? data.Rows.Count / 100 : (data.Rows.Count / 100 + 1);
labToal.Text = "/" + Tnum;//AS a ORDER BY ID DESC
data.Clear();
backgroundDowork(Cnum);

 background-DoWorker

加一个

if (i +1==100)
{
//data.Clear();
break;
}

分页主要代码

private void toolStripLabel2_Click(object sender, EventArgs e)//页数减
{
if (Cnum > 0)
{
Cnum--;
backgroundDowork(Cnum);
}
}
private void toolStripLabel3_Click(object sender, EventArgs e)//页数加
{

if (Cnum >=0)
{
Cnum++;
backgroundDowork(Cnum);

}
}
public void backgroundDowork(int Cnum)
{
if (Cnum >= 0)
{
txtCurrentPage.Text = Cnum.ToString();
if (backgroundWorker1.IsBusy) return;
var sql1 = string.Format(
"select top 100 *from(select top " + Cnum * 100 +
" *from history where datetime>='{0}' and datetime<'{1}' and connection='{2}' and batgroup='{3}' ORDER BY datetime DESC) AS a ORDER BY datetime ASC",
dateTimePicker1.Value.ToString("yyyy-MM-dd HH:mm:00"),
dateTimePicker2.Value.AddMinutes(1).ToString("yyyy-MM-dd HH:mm:00"), comboBox1.Text,
comboBox2.Text);
if (Cnum <= Tnum&&Cnum>0)
{
backgroundWorker1.RunWorkerAsync(sql1);
listView1.VirtualListSize = 0;
}
else
listView1.Items.Clear();

}
}

private void btnFirst_Click(object sender, EventArgs e)
{
backgroundDowork(1);
}

private void btnlast_Click(object sender, EventArgs e)
{
backgroundDowork(Tnum);
}

private void toolStripButton1_Click(object sender, EventArgs e)
{
var num = Convert.ToInt32(txtCurrentPage.Text);
backgroundDowork(num);
}

 

转载于:https://www.cnblogs.com/Never-Die/p/7815668.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值