protected override void OnLoad(EventArgs e) { // Initialize the form. this.AutoSize = true; this.Controls.Add(this.dataGridView1); this.Text = "DataGridView virtual-mode just-in-time demo"; // Complete the initialization of the DataGridView. this.dataGridView1.Size = new Size(800, 250); this.dataGridView1.Dock = DockStyle.Fill; this.dataGridView1.VirtualMode = true; this.dataGridView1.ReadOnly = true; this.dataGridView1.AllowUserToAddRows = false; this.dataGridView1.AllowUserToOrderColumns = false; this.dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect; this.dataGridView1.CellValueNeeded += new DataGridViewCellValueEventHandler(dataGridView1_CellValueNeeded); // Create a DataRetriever and use it to create a DataGridViewCache object // and to initialize the DataGridView columns and rows. try { DataRetriever retriever = new DataRetriever(m_DBCon, table, "select * from tbLog"); memoryCache = new DataGridViewCache(retriever, 16); foreach (DataColumn column in retriever.Columns) { dataGridView1.Columns.Add(column.ColumnName, column.ColumnName); } this.dataGridView1.RowCount = retriever.RowCount; } catch (MySqlException ex) { cErr.showError(ex, "Connection could not be established. " + "Verify that the connection string is valid."); Application.Exit(); } // Adjust the column widths based on the displayed values. this.dataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.DisplayedCells); base.OnLoad(e); }