c# - 在虚拟模式下,我的datagridview在多次加载时出现渣滓
问题描述
我正在使用带缓存的虚拟模式在我的 WinForms 应用程序中加载我的 datagridview,使用的代码与此处相同
更改了SupplyData
功能以能够搜索如下数据
public DataTable SupplyPageOfData(int lowerPageBoundary, int rowsPerPage)
{
// Store the name of the ID column. This column must contain unique
// values so the SQL below will work properly.
columnToSortBy = this.Columns[0].ColumnName;
//if (!this.Columns[columnToSortBy].Unique)
//{
// throw new InvalidOperationException(String.Format(
// "Column {0} must contain unique values.", columnToSortBy));
//}
// Retrieve the specified number of rows from the database, starting
// with the row specified by the lowerPageBoundary parameter.
command.CommandText = "Select CPNum, strftime('%d-%m-%Y', CPEdtDate) AS CPEdtDate From " + tableName + " WHERE CPNum LIKE '%" + search + "%' AND " + columnToSortBy + " NOT IN (SELECT " + columnToSortBy + " From " +
tableName + " WHERE CPNum LIKE '%" + search + "%' Order By " + columnToSortBy + " LIMIT " + lowerPageBoundary + ") Order By " + columnToSortBy + " LIMIT " + rowsPerPage;
adapter.SelectCommand = command;
DataTable table = new DataTable();
table.Locale = CultureInfo.InvariantCulture;
adapter.Fill(table);
return table;
}
重新加载网格时,我使用以下代码
DataRetriever retriever =
new DataRetriever(connectionString, table, search);
memoryCache = new Cache(retriever, 16);
foreach (DataColumn column in retriever.Columns)
{
if (!masterChartGrid.Columns.Contains(column.ColumnName))
{
masterChartGrid.Columns.Add(
column.ColumnName, "Edition Date");
}
}
masterChartGrid.Rows.Clear();
this.masterChartGrid.RowCount = retriever.RowCount;
它适用于搜索数据。但是当我再次尝试重置搜索和重新加载表时,应用程序变得无响应。
解决方案
当我从.cs
文件中以编程方式添加 DataGridView 时,它起作用了。
private DataGridView masterChartGrid = new DataGridView();
推荐阅读
- javascript - 带有反应的本地网络分析仪
- sql - 如何避免在开始 SQL 查询时删除的表上出现错误?
- java - 使用 Spark 和 java 编写 CSV 文件 - 处理空值和引号
- android - 如何在 XML GridView 中使宽度比相等
- angular - 如何以角度将数组绑定到ngModel并检测更改
- python - 什么会导致 sock connect() 命令出现“资源暂时不可用”
- c++ - 如果我不使用 C++11,如何实现 std::move() 替代方案?
- php - 为什么模型/变量保持其价值?
- angular - 使用 RxJs ConcatMap 不要发送 null 值或空字符串
- c++ - 首次访问时分配的智能指针