Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8741617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:20:53+00:00 2026-06-13T11:20:53+00:00

A general question for advice on the implementation. I’ve got a collection bound to

  • 0

A general question for advice on the implementation.

I’ve got a collection bound to a datagridview.

BindingList<Line> allLines = new BindingList<Line>();
dataGridView1.DataSource = allLines;

I want to implement virtual mode because the collection could contain millions of entries (Line objects) so I thought it may be quicker to only ‘cache’ or display a few entries that are needed at a time. Which is what I understand virtual mode to be for?

I’ve looked at: http://msdn.microsoft.com/en-us/library/2b177d6d.aspx

But I can’t get it to work for a datagridview that is databound.

I can’t specify the row count:

this.dataGridView1.RowCount = 20;
`RowCount property cannot be set on a data-bound DataGridView control.`

EDIT: this link suggests I may have to remove the binding completely. Is this the case? http://msdn.microsoft.com/en-us/library/ms171622.aspx

‘If bound mode does not meet your performance needs, you can manage all your data in a custom cache through virtual-mode event handlers.’

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:20:54+00:00Added an answer on June 13, 2026 at 11:20 am

    If you want to use DataGridView.VirtualMode, then you’re not expected to use bound data set. They atr opposites. So, you don’t set DataSource, but just set the RowCount property and provide an event handler for DataGridView.CellValueNeeded Event.

    Besides you need to set dataGridView.VirtualMode property to true first, probably write in the designer. By default it’s set to false, that’s why you get an exception, saying you cannot set RowCount.

    Probably you’ll have to manually initialize grid’s columns.

    While refreshing your grid (say, on button click), you’ll have to

    dataGridView.RowCount = 0;
    \\refresh your cache, where you store rows for the grid
    \\...
    dataGridView.RowCount = yourCache.Count;//or some other property, getting the number of cached rows.
    

    The CellValueNeeded event will be fired for each column of each row, depending on the RowCount and the number of columns. You’re expected to set e.Value with the value of the processed cell in your event handler depending on the e.RowIndex and e.ColumnIndex.

    So, for this to work you’ll need at least to handle CellValueNeeded. If your DataGridView is readonly, others events are not necessary.

    A more complete and consecutive overview is available at Virtual Mode in the Windows Forms DataGridView Control.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

More of a general MATLAB question than looking for programming advice -- if I
I have a general question about the new Django 1.3 static file framework. I
Though the question is very specific, I'd also really appreciate general advice and other
I have a more general question but any advice in implementing this in C#
So I've seen this question , but I'm looking for some more general advice:
general question is i like to build logger class that writes to single log
General question about java servlets and the best way to handle requests. If I
I have a general question on the class definition and its use..THe below code
Sorry for the fairly general question but I am looking to find out what
I guess my general question which I googled to no luck: Is there a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.