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. Visual Basic
  4. Modify the number of rows that a datagridview can show instantly , on runtime

Modify the number of rows that a datagridview can show instantly , on runtime

Scheduled Pinned Locked Moved Visual Basic
tutorialquestion
13 Posts 3 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 dilkonika

    Hello ! Is there any possibility to modify the number of rows that a datagridview can show instantly ? For example a datagridview can show 12 record instantly. On runtime , is possible to make a modifications in order that the datagridview to show 10 records instantly ( the remaining datagridview area can be empty ). Thank you !

    S Offline
    S Offline
    Sascha Lefevre
    wrote on last edited by
    #2

    What do you mean by "can show instantly"? The vertical size of the DataGridView?

    D 1 Reply Last reply
    0
    • S Sascha Lefevre

      What do you mean by "can show instantly"? The vertical size of the DataGridView?

      D Offline
      D Offline
      dilkonika
      wrote on last edited by
      #3

      I mean can show together in one page. I want to modify this number ( but without changing the datagridview vertical size. )

      S 1 Reply Last reply
      0
      • D dilkonika

        I mean can show together in one page. I want to modify this number ( but without changing the datagridview vertical size. )

        S Offline
        S Offline
        Sascha Lefevre
        wrote on last edited by
        #4

        If you don't use the DataGridView in databound-mode then you can set the number of rows displayed with its .RowCount-property. In databound-mode that is not possible.

        D 1 Reply Last reply
        0
        • S Sascha Lefevre

          If you don't use the DataGridView in databound-mode then you can set the number of rows displayed with its .RowCount-property. In databound-mode that is not possible.

          D Offline
          D Offline
          dilkonika
          wrote on last edited by
          #5

          No it's databound-Mode. So you think there's no possibility to do that ?

          S 1 Reply Last reply
          0
          • D dilkonika

            No it's databound-Mode. So you think there's no possibility to do that ?

            S Offline
            S Offline
            Sascha Lefevre
            wrote on last edited by
            #6

            If you want to restrict the amount of rows in databound-mode then you have to restrict the amount of rows in the datasource. If your datasource is a DataView of a DataTable with some integer as primary key (or just any unique integer column) you could use the .RowFilter-property of the DataView to filter from the total rows the rows that should currently be displayed, e.g.:

            dataView.RowFilter = "idColumn >= 10 AND idColumn < 20"

            If the values of that column aren't consecutive you would have to scan the rows before and determine the actual value of that column at the position that should be the last on the page.

            D 1 Reply Last reply
            0
            • S Sascha Lefevre

              If you want to restrict the amount of rows in databound-mode then you have to restrict the amount of rows in the datasource. If your datasource is a DataView of a DataTable with some integer as primary key (or just any unique integer column) you could use the .RowFilter-property of the DataView to filter from the total rows the rows that should currently be displayed, e.g.:

              dataView.RowFilter = "idColumn >= 10 AND idColumn < 20"

              If the values of that column aren't consecutive you would have to scan the rows before and determine the actual value of that column at the position that should be the last on the page.

              D Offline
              D Offline
              dilkonika
              wrote on last edited by
              #7

              If a apply a filter , then the vertical scrollbar will be hide , and the user may think that there are no more records in the gridview.

              S 1 Reply Last reply
              0
              • D dilkonika

                If a apply a filter , then the vertical scrollbar will be hide , and the user may think that there are no more records in the gridview.

                S Offline
                S Offline
                Sascha Lefevre
                wrote on last edited by
                #8

                The vertical scrollbar doesn't hide when applying a filter, unless the filter restricts the amount of rows to less than the height of the DataGridView. If that's not true for your DataGridView the reason must be somewhere else.

                D 1 Reply Last reply
                0
                • S Sascha Lefevre

                  The vertical scrollbar doesn't hide when applying a filter, unless the filter restricts the amount of rows to less than the height of the DataGridView. If that's not true for your DataGridView the reason must be somewhere else.

                  D Offline
                  D Offline
                  dilkonika
                  wrote on last edited by
                  #9

                  Yes , but if you read my first post , this is what I want t o do. Actually gridview has for example , 36 records and he show 12 records per page. I want to reduce this number for example to 10. but the total height of 10 records is less than gridview height , so if I apply a filter to show 10 records , the vertical scrollbar will be hidden.

                  S 1 Reply Last reply
                  0
                  • D dilkonika

                    Yes , but if you read my first post , this is what I want t o do. Actually gridview has for example , 36 records and he show 12 records per page. I want to reduce this number for example to 10. but the total height of 10 records is less than gridview height , so if I apply a filter to show 10 records , the vertical scrollbar will be hidden.

                    S Offline
                    S Offline
                    Sascha Lefevre
                    wrote on last edited by
                    #10

                    Alright, but what would a visible scrollbar change about the user possibly thinking that there are no more records when he scrolls to the end but in fact there are still more records? You will have to indicate that by something better than a scrollbar. Didn't you want to display something like <prev> 1 2 3 4 5 <next>? That would inform the user about more records.

                    D 1 Reply Last reply
                    0
                    • S Sascha Lefevre

                      Alright, but what would a visible scrollbar change about the user possibly thinking that there are no more records when he scrolls to the end but in fact there are still more records? You will have to indicate that by something better than a scrollbar. Didn't you want to display something like <prev> 1 2 3 4 5 <next>? That would inform the user about more records.

                      D Offline
                      D Offline
                      dilkonika
                      wrote on last edited by
                      #11

                      the reason why I want this behavior , is because sometimes the last record on a page is not full displayed. So the gridview shows 12 , but the last record is not full displayed. so I want to reduce the number to 11 or 10. I know that I can make this by changing the gridview's height on design to full display the last record, but on runtime the user can resize the row's height so will be the same situation

                      S L 2 Replies Last reply
                      0
                      • D dilkonika

                        the reason why I want this behavior , is because sometimes the last record on a page is not full displayed. So the gridview shows 12 , but the last record is not full displayed. so I want to reduce the number to 11 or 10. I know that I can make this by changing the gridview's height on design to full display the last record, but on runtime the user can resize the row's height so will be the same situation

                        S Offline
                        S Offline
                        Sascha Lefevre
                        wrote on last edited by
                        #12

                        But what would be the use of a visible ScrollBar if there is nothing to scroll? My advice would be: Do whatever you want with the amount of records displayed but don't bother with the scrollbar. If it's needed for scrolling, it will be shown, otherwise not. If there are more records than on the current page, inform the user by showing the page-selection-controls. If you absolutely want to have an always visible scrollbar you will have to do some extra work: https://social.msdn.microsoft.com/forums/windows/en-us/516851de-ac00-4442-b846-44734dcbd7f5/always-display-vertical-scrollbar-in-datagridview[^]

                        1 Reply Last reply
                        0
                        • D dilkonika

                          the reason why I want this behavior , is because sometimes the last record on a page is not full displayed. So the gridview shows 12 , but the last record is not full displayed. so I want to reduce the number to 11 or 10. I know that I can make this by changing the gridview's height on design to full display the last record, but on runtime the user can resize the row's height so will be the same situation

                          L Offline
                          L Offline
                          Lost User
                          wrote on last edited by
                          #13

                          Alternatively; DataGridView With Paging (UserControl)[^].

                          Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

                          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