Results 1 to 5 of 5

Thread: Selecting row in Datagridview

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Posts
    394

    Selecting row in Datagridview

    I have a datagridview that gets populatedfrom an XML file when the form loads. One of the XML fields indicates which datagridview row was selected when the application closed. When I load the form and I can find the row and set it to "selected". This works and the row gets highlighted (selected = true) the problem that I'm having is the row selector (little black triangle on the left) always points to the first row until the user clicks the grid. After that the highlighted row and the row selector agree. Is there another property to set the row selector?


    Here's the code that I'm using to select the row.
    vb Code:
    1. For i = 0 To dsLoads.Tables("Loads").Rows.Count - 1
    2.     dv = Me.grdLoads.Item("loaded", i)
    3.     If CType(dv.Value, Integer) = 1 Then
    4.         row = i
    5.         grdLoads.Rows(row).Selected = True
    6.     End If
    7. Next

  2. #2
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: Selecting row in Datagridview

    Hi,

    Here's a link how to selecting a row in a Datagridview.

    http://msdn2.microsoft.com/en-us/lib...ectedrows.aspx


    Wkr,

    sparrow1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Posts
    394

    Re: Selecting row in Datagridview

    Thanks Sparrow, but that is a link on how to manipulate rows that have been selected by the user. I am programatically selecting the row. As I mentioned in my original post, my code will select the correct row but the DGV row selected indicator ( I don't know what it's reaaly called) does not match the selected row. If I use a message bos to display the contents of the selected row I get what I would expect. My problem is that users thinks that row one is selected (when it's not) because of te little black pointer on the left.

    I can always just reduce the size of the row header until the pointer is not visible but I was looking for the "real" answer.

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

    Re: Selecting row in Datagridview

    Try setting the CurrentCell property to a cell in that row. That's a stab in the dark but it may work.
    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

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Posts
    394

    Re: Selecting row in Datagridview

    Nice Stab. Worked great, thanks.

    vb Code:
    1. grdLoads.CurrentCell = grdLoads(0, i)

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