在虚拟模式下,加载多个时间时我的datagridview结渣

问题描述 投票:0回答:1

我正在使用虚拟模式进行缓存,以使用可用的相同代码将我的datagridview加载到WinForms应用程序中here

已更改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;

对于搜索数据来说效果很好。但是,当我尝试重设搜索并重新加载表时,应用程序变得无响应。

c# .net winforms datagridview virtual
1个回答
0
投票

当我以编程方式从.cs文件添加DataGridView时,它起作用。

private DataGridView masterChartGrid = new DataGridView();

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.