Results 1 to 3 of 3

Thread: datagridview selected row

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2006
    Posts
    719

    datagridview selected row

    i use this code to select a curent row

    dgvProduct.Rows(iCount).Selected = True

    but the cursor (|>) something like was still on the first row of the grid.. what should I do?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: datagridview selected row

    In DataGridView terms, "selected" just means highlighted. Given that multiple rows can be selected at the same time, it couldn't mean anything else.

    The row that contains focus is actually the current row, which is accessed via the CurrentRow property. That property is ReadOnly though, so you can't set it. It is simply defined as the row containing the CurrentCell, which you can set.

    If you index the grid itself by column and row, you are invoking the Item property and that will return the cell at those coordinates. You can then assign that cell to the CurrentCell property and that will also implicitly set the CurrentRow and CurrentCellAddress properties.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Member
    Join Date
    Jun 2012
    Posts
    43

    Re: datagridview selected row

    You can also use the FirstDisplayedScrollingRowIndex property of the datagridview to show the row you want without selecting it. e.g.

    dgvProducts.FirstDisplayedScrollingRowIndex = icount

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width