Results 1 to 7 of 7

Thread: How to programmaticly select a row in datagridview and update its child grid?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2008
    Posts
    110

    How to programmaticly select a row in datagridview and update its child grid?

    I bind datagridview 2 as a child of dgv1 by defining a relation.

    I need to select a row in dgv1 on demand. I do this be setting the row.selected=true, but dgv2 cannot be automatically updated until I have to click the row in dgv1.

    How to do this automaically?

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: How to programmaticly select a row in datagridview and update its child grid?

    You can programmatically do a button click by calling its PerformClick method.
    Code:
    'after you've selected a row, do click the button using code
    Button1.PerformClick() 'Of course, you have to replace Button1 with the correct button
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2008
    Posts
    110

    Re: How to programmaticly select a row in datagridview and update its child grid?

    Thanks for help.

    But I need to click the row programmatically rather then a button.

    You mean I have to host a button in each row? it is unacceptable.

  4. #4
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: How to programmaticly select a row in datagridview and update its child grid?

    Move whatever code you have in your click event handler to its own subroutine then you can call the sub directly when ever you like.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jun 2008
    Posts
    110

    Re: How to programmaticly select a row in datagridview and update its child grid?

    Sorry, I still cannot get your point.

    DataGridView doesn't have a method like PerformClick.

    What I need is for two DGV having relation (one is parent and other is child),

    When I click a row in parent, the child is auto updated accordingly.

    But how can I perform this update programmically?

  6. #6
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: How to programmaticly select a row in datagridview and update its child grid?

    You already have a click event handler to handle the row/cell click event of your datagridview, right? In that event handler, you have code written, right? So all you have to do is declare a subroutine and move the code in the event handler to that sub. That way, you can call the sub whenever you want, and it will run whatever code you need just as you do a click.
    So, basically, instead of doing this:
    Code:
    Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
            MessageBox.Show("Hello!")
        End Sub
    You just change the code to this
    Code:
    Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
            Foo()
        End Sub
    
        Private Sub Foo()
            MessageBox.Show("Hello!")
        End Sub
    And you can call Foo() whenever you like, it doesn't have to be in a click event handler.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jun 2008
    Posts
    110

    Re: How to programmaticly select a row in datagridview and update its child grid?

    Yes I understand what you said.

    But please be informed that by defining relation on a dataset and assigning to child binding source, I needn't write any code in the click event of row.
    The update is done automatically, maybe hidden in VB.NET

    What I am asking is how to explicitly call the update.

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