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. how to:C# Datagridview must show only fixed number of rows

how to:C# Datagridview must show only fixed number of rows

Scheduled Pinned Locked Moved C#
csharpdatabasesql-serverwinformssysadmin
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.
  • C Offline
    C Offline
    Cobusvdvyver
    wrote on last edited by
    #1

    Good day all. This is the first time I ask a question here, but have been using codeproject for some time now. Great site - Good work! Im doing a C# windows forms application that reads data from Windows Sql Server Express and then displays the data from a specific table in a datagridview (im using bindingsource). This is no problem. The problem is my table is quite large more than a thousand rows. Currently all the data displays at one time with vertical scroll bars to scroll down. But I would like to only display a fixed number of rows, say the last 10 entries. Is this at all possible. Hope this question has not been asked before. Searched through a bunch of forums and websites and could not get the right question with an answer. Thanks in advance. Cobus

    C 1 Reply Last reply
    0
    • C Cobusvdvyver

      Good day all. This is the first time I ask a question here, but have been using codeproject for some time now. Great site - Good work! Im doing a C# windows forms application that reads data from Windows Sql Server Express and then displays the data from a specific table in a datagridview (im using bindingsource). This is no problem. The problem is my table is quite large more than a thousand rows. Currently all the data displays at one time with vertical scroll bars to scroll down. But I would like to only display a fixed number of rows, say the last 10 entries. Is this at all possible. Hope this question has not been asked before. Searched through a bunch of forums and websites and could not get the right question with an answer. Thanks in advance. Cobus

      C Offline
      C Offline
      Cobusvdvyver
      wrote on last edited by
      #2

      Sorry to answer my own question, but I found a solution: Instead of using the datagridview to show only the newest 10 entries I changed my SQL Query which will fill my datatable to:

      SELECT TOP 10 Column1,Column2
      FROM Table_Name
      ORDER BY Column1 DESC

      This result is then the 10 most recent entries in the table. Without the DESC keyword the first 10 entries will be displayed Thank you in any case.

      M 1 Reply Last reply
      0
      • C Cobusvdvyver

        Sorry to answer my own question, but I found a solution: Instead of using the datagridview to show only the newest 10 entries I changed my SQL Query which will fill my datatable to:

        SELECT TOP 10 Column1,Column2
        FROM Table_Name
        ORDER BY Column1 DESC

        This result is then the 10 most recent entries in the table. Without the DESC keyword the first 10 entries will be displayed Thank you in any case.

        M Offline
        M Offline
        Mycroft Holmes
        wrote on last edited by
        #3

        Cobusvdvyver wrote:

        Sorry to answer my own question, but I found a solution:

        Its never a bad thing to answer your own question, it shows you are working and not just waiting for the codz to be sent to you. Also feedback on the solution may help another and stops those who help from spending resources on an answered question. So have 5 and keep it up.

        Never underestimate the power of human stupidity RAH

        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