现在用C#做的WINFORM平台。。涉及到了datagridview分页问题。
如果数据量小的话还看不出什么问题,当数据量大的时候就会出现如下问题。比如 每页显示10条数据,如果我跳转到第98页,有时候就会出现98页是空白的情况,或者连续两页数据相同的情况,比如98 99两页的内容是相同的。不知道为什么。求大神
如果数据量小的话还看不出什么问题,当数据量大的时候就会出现如下问题。比如 每页显示10条数据,如果我跳转到第98页,有时候就会出现98页是空白的情况,或者连续两页数据相同的情况,比如98 99两页的内容是相同的。不知道为什么。求大神
解决方案 »
- FCKeditor上传图片问题
- 数据访问层性能问题,DataTable和SqlDataReader-> List<T>比较
- TabControl 怎么放背景呢?
- .Net(C#) 导入注册表,出现的问题~
- .net中点击控件页面刷新问题
- 平时没努力 临时烧香拜佛 C#课程设计
- 跪求 大虾们 帮下小弟 解决下这查询问题~~改下 下面的代码
- 第一次提问,您的回复,我的动力!问题很简单……
- 正则提取
- C#(winform) 如何在Datagridview添加一列按钮列,实现对数据的编辑
- winform问题:在可以调用 OLE 之前,必须将当前线程设置为单线程单元(STA)模式
- 貌似关于多线程的一个问题
{
while (true)
{
out_pagecount(); //计算需要多少页显示
t_interfaceupdate(); //界面刷新
t_sqltodgv(); //绑定数据
Thread.Sleep(MessageModem.Properties.Settings.Default.pageUDTime);
}
} private int out_historycount( ) //计算历史记录中记录的条数 ,返回结果 historycount
{
SqlConnection sqlConnection = new SqlConnection(MessageModem.Properties.Settings.Default.ConnString);
sqlConnection.Open();
SqlCommand mysqlcommand2 = new SqlCommand("select count(*) from t_history", sqlConnection);
int historycount = (int)mysqlcommand2.ExecuteScalar();
sqlConnection.Close(); return historycount;
} private void out_pagecount( ) //计算历史记录中数据需要多少页显示,赋值给pageCount
{
try
{
int recordcount = out_historycount( );
pageCount = (pageSize + recordcount - 1) / pageSize;
}
catch (Exception ex)
{
MessageBox.Show(ex.TargetSite.ToString()+" :"+ex.Message, "出错啦!");
}
} private void t_interfaceupdate() //标签界面刷新
{
if (this.panel1.InvokeRequired)
{
FlushClient fc = new FlushClient(t_interfaceupdate);
this.Invoke(fc);
}
else
{
this.label5.Text = string.Format("{0}/{1}页", currentPage + 1, pageCount);
if (currentPage <= 0)
this.button_front.Enabled = false;
else
this.button_front.Enabled = true;
if (currentPage >= pageCount - 1)
this.button_behind.Enabled = false;
else
this.button_behind.Enabled = true;
}
} private void t_sqltodgv() // 将DataGridView与数据表绑定。
{
if (this.panel1.InvokeRequired)//等待异步
{
FlushClient fc = new FlushClient(t_sqltodgv);
this.Invoke(fc);//通过代理调用刷新方法
}
else
{
SqlConnection sqlConnection = new SqlConnection(MessageModem.Properties.Settings.Default.ConnString);
sqlConnection.Open();
string mysql = string.Format("select top {0} * from t_history where 时间 not in "
+"(select top {1} 时间 from t_history order by 时间 desc) order by 时间 desc",pageSize,pageSize * currentPage);
SqlCommand mysqlcommand = new SqlCommand( mysql, sqlConnection );
SqlDataAdapter data = new SqlDataAdapter();
data.SelectCommand = mysqlcommand;
DataSet data2 = new DataSet();
data.Fill(data2);
dataGridView1.DataSource = data2.Tables[0];
this.dataGridView1.Columns[0].FillWeight = 27; //设置每行相对宽度,百分比
this.dataGridView1.Columns[1].FillWeight = 12;
this.dataGridView1.Columns[2].FillWeight = 12;
this.dataGridView1.Columns[3].FillWeight = 17;
this.dataGridView1.Columns[4].FillWeight = 32; sqlConnection.Close();
}
}