DataGridView making a row visible

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

    DataGridView making a row visible

    Hi,
    I need to tell how many rows are visible on the screen,
    in my DataGridView control
    so that I can ensure my newly selected row is visible
    without doing any unecessry scrolling,

    I thought RowCount would give me this :-
    Summary:
    Gets or sets the number of rows displayed in the
    System.Windows. Forms.DataGridV iew.

    but this isnt meaning the number dispalyed on the screen,
    im not sure what it is, it serems to be the same as the number of rows in
    the coollection.
    I gues it just truncates the number of rows.

    it conveniently tells you the first visible row
    but not the last it seems, unless I am missing something.

    is there another way to get this info ?
    or do i have to work it out using pixels :s

    Colin =^.^=


  • Greg

    #2
    Re: DataGridView making a row visible

    On Dec 31, 1:33 pm, "colin" <colin.ro...@nt world.NOSPAM.co mwrote:
    Hi,
     I need to tell how many rows are visible on the screen,
    in my DataGridView control
    so that I can ensure my newly selected row is visible
    without doing any unecessry scrolling,
    >
    I thought RowCount would give me this :-
    Summary:
    Gets or sets the number of rows displayed in the
    System.Windows. Forms.DataGridV iew.
    >
    but this isnt meaning the number dispalyed on the screen,
    im not sure what it is, it serems to be the same as the number of rows in
    the coollection.
    I gues it just truncates the number of rows.
    >
    it conveniently tells you the first visible row
    but not the last it seems, unless I am missing something.
    >
    is there another way to get this info ?
    or do i have to work it out using pixels :s
    >
    Colin =^.^=
    I thought RowCount would have worked too.
    However, if you want to show your newly 'selected' row,
    then simply use DataGridView.Fi rstDisplayedScr ollingRowIndex =
    rowIndex.

    Greg

    Comment

    • colin

      #3
      Re: DataGridView making a row visible

      >"Greg" <gcadmes@gmail. comwrote in message
      >news:203e78a 2-16e1-42c9-baa3-5f16fbeaed5b@e1 0g2000prf.googl egroups.com...
      >On Dec 31, 1:33 pm, "colin" <colin.ro...@nt world.NOSPAM.co mwrote:
      Hi,
      >.>I need to tell how many rows are visible on the screen,
      >in my DataGridView control
      >so that I can ensure my newly selected row is visible
      >without doing any unecessry scrolling,
      >>
      >I thought RowCount would give me this :-
      >Summary:
      >Gets or sets the number of rows displayed in the
      >System.Windows .Forms.DataGrid View.
      >>
      >but this isnt meaning the number dispalyed on the screen,
      >im not sure what it is, it serems to be the same as the number of rows in
      >the coollection.
      >I gues it just truncates the number of rows.
      >>
      >it conveniently tells you the first visible row
      >but not the last it seems, unless I am missing something.
      >>
      >is there another way to get this info ?
      >or do i have to work it out using pixels :s
      >>
      >Colin =^.^=
      >I thought RowCount would have worked too.
      >However, if you want to show your newly 'selected' row,
      >then simply use DataGridView.Fi rstDisplayedScr ollingRowIndex =
      >rowIndex.
      >
      >Greg
      ah yes I do that already, I realy thought id mentioned that.. oh well,
      anyway that scrolls the selection to be at the top of the list always,
      but the selection is set via a mousehover on a 3d graphical object,
      wich are wireframe models,
      when the mouse is moving accros several objects
      its scrolling up and down like crazy and its a bit of a pain.

      I had hoped to only scroll up or down as few lines as possible to bring it
      into view,
      for now im just assuming theres 8 lines.

      for(int i=0;i < grid.Rows.Count ;i++)
      {
      if(grid.Rows[i].Tag == selection)
      {
      if (!grid.Rows[i].Selected)
      {
      grid.ClearSelec tion();
      grid.Rows[i].Selected = true;
      if (i < grid.FirstDispl ayedScrollingRo wIndex)
      grid.FirstDispl ayedScrollingRo wIndex = i;
      else if (i >= grid.FirstDispl ayedScrollingRo wIndex + 8)
      grid.FirstDispl ayedScrollingRo wIndex = i - (8-1);

      Colin =^.^=


      Comment

      Working...