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?
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
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.
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.
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?
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.
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.