Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. DataGridView, DataSource and RowCount related query

DataGridView, DataSource and RowCount related query

Scheduled Pinned Locked Moved C#
questiondatabasecom
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dan sh
    wrote on last edited by
    #1

    Couldn't think of a decent subject. sorry. If I add a DataGridView to a Form in constructor and create and set its datasource there itself. Now, I also check the rowcount in the constructor and it comes out as zero. Can someone explain the reason? Here[^] is the question that triggered mine.

    50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!

    B 1 Reply Last reply
    0
    • D dan sh

      Couldn't think of a decent subject. sorry. If I add a DataGridView to a Form in constructor and create and set its datasource there itself. Now, I also check the rowcount in the constructor and it comes out as zero. Can someone explain the reason? Here[^] is the question that triggered mine.

      50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!

      B Offline
      B Offline
      Ben Fair
      wrote on last edited by
      #2

      I believe this is because the RowCount property is related to the rows visually represented by the DataGridView control. According to your steps, after the constructor has run you have a DataGridView control and a DataSource attached to it that is filled with data, but the DataGridView control hasn't done it's visual rendering yet. If you check the property after the DataGridView has been rendered and displayed at least one time, you should get the expected value. Try placing an event handler on the Form.Shown event and then put a break point in the handler and check the RowCount property.

      Hold on a second here... Don't you think you might be putting the horse ahead of the cart?

      D 1 Reply Last reply
      0
      • B Ben Fair

        I believe this is because the RowCount property is related to the rows visually represented by the DataGridView control. According to your steps, after the constructor has run you have a DataGridView control and a DataSource attached to it that is filled with data, but the DataGridView control hasn't done it's visual rendering yet. If you check the property after the DataGridView has been rendered and displayed at least one time, you should get the expected value. Try placing an event handler on the Form.Shown event and then put a break point in the handler and check the RowCount property.

        Hold on a second here... Don't you think you might be putting the horse ahead of the cart?

        D Offline
        D Offline
        dan sh
        wrote on last edited by
        #3

        That is what I had in mind as well. Let us see if we get a confirmation. :)

        50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups