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

效果图

Winform ListView分页控件从其他地方查询获取数据_第1张图片

通过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

你可能感兴趣的:(Winform ListView分页控件从其他地方查询获取数据)