Stepping through datagridview rows in code

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • steve

    #1

    Stepping through datagridview rows in code

    Hi All

    I have a datagridview bound to a datatable

    Due to the use of touch screens I need to be able to scroll the grid in code
    in response to a button click
    i.e each button touch (click) will move the selection up 1 row

    How do I do that


    Regards
    Steve


  • Chris

    #2
    Re: Stepping through datagridview rows in code

    steve wrote:[color=blue]
    > Hi All
    >
    > I have a datagridview bound to a datatable
    >
    > Due to the use of touch screens I need to be able to scroll the grid in code
    > in response to a button click
    > i.e each button touch (click) will move the selection up 1 row
    >
    > How do I do that
    >
    >
    > Regards
    > Steve
    >
    >[/color]

    You need to change the current cell. I don't remember the exact code
    but it'll be something like:

    DataGridView.Cu rrentCell = DataGridView.Ro ws(RowIndex -1).Cells(0)

    of course you need to check that it's not less than 0

    Chris

    Comment

    • Walter Wang [MSFT]

      #3
      RE: Stepping through datagridview rows in code

      Hi Steve,

      Thank you for posting!

      To simply scroll the DataGridView without changing selected rows, you can
      use the property FirstDisplayedS crollRowIndex,

      To change the selection while scrolling, you can first get the current
      selected row's index by "DataGridView1. SelectedRows(0) .Index", then you can
      determine the index of next or previous row. Then use following code to
      change selection:

      DataGridView1.R ows(newindex).S elected = True

      Though you may need to set the DataGridView's selection mode to single
      selection first:

      DataGridView1.S electionMode = DataGridViewSel ectionMode.Full RowSelect
      DataGridView1.M ultiSelect = False


      If there's anything unclear, please feel free to post here.

      Regards,

      Walter Wang
      Microsoft Online Community Support

      =============== =============== =============== =====
      When responding to posts, please "Reply to Group" via your newsreader so
      that others may learn and benefit from your issue.
      =============== =============== =============== =====

      This posting is provided "AS IS" with no warranties, and confers no rights.

      Comment

      • steve

        #4
        Re: Stepping through datagridview rows in code

        Hi Walter

        Just what I needed

        Thanks heaps

        Regards
        Steve

        "Walter Wang [MSFT]" <wawang@online. microsoft.com> wrote in message
        news:h3kqh1UfGH A.5992@TK2MSFTN GXA01.phx.gbl.. .[color=blue]
        > Hi Steve,
        >
        > Thank you for posting!
        >
        > To simply scroll the DataGridView without changing selected rows, you can
        > use the property FirstDisplayedS crollRowIndex,
        >
        > To change the selection while scrolling, you can first get the current
        > selected row's index by "DataGridView1. SelectedRows(0) .Index", then you
        > can
        > determine the index of next or previous row. Then use following code to
        > change selection:
        >
        > DataGridView1.R ows(newindex).S elected = True
        >
        > Though you may need to set the DataGridView's selection mode to single
        > selection first:
        >
        > DataGridView1.S electionMode = DataGridViewSel ectionMode.Full RowSelect
        > DataGridView1.M ultiSelect = False
        >
        >
        > If there's anything unclear, please feel free to post here.
        >
        > Regards,
        >
        > Walter Wang
        > Microsoft Online Community Support
        >
        > =============== =============== =============== =====
        > When responding to posts, please "Reply to Group" via your newsreader so
        > that others may learn and benefit from your issue.
        > =============== =============== =============== =====
        >
        > This posting is provided "AS IS" with no warranties, and confers no
        > rights.
        >[/color]


        Comment

        • Cor Ligthert [MVP]

          #5
          Re: Stepping through datagridview rows in code

          Steve.

          Try to avoid for every bounded control to access it direct. Use the
          currencymanager , where you than are playing with the position of that.

          http://msdn.microsoft.com/library/de...classtopic.asp

          I hope this helps,

          Cor

          "steve" <ga630sf@newsgr oups.nospam> schreef in bericht
          news:exCYRrSfGH A.3572@TK2MSFTN GP04.phx.gbl...[color=blue]
          > Hi All
          >
          > I have a datagridview bound to a datatable
          >
          > Due to the use of touch screens I need to be able to scroll the grid in
          > code in response to a button click
          > i.e each button touch (click) will move the selection up 1 row
          >
          > How do I do that
          >
          >
          > Regards
          > Steve
          >[/color]


          Comment

          Working...