[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 374
  • Last Modified:

Vb.net 2008 Datagridview event

I have a datagridview already populate with data. user click and select one row. then it will query DB and display the result on other datagribview.

i would like to know what datagridview event is best or suitable. to do fire the query code.
0
aarontham
Asked:
aarontham
  • 4
  • 2
  • 2
1 Solution
 
Jorge PaulinoIT Pro/DeveloperCommented:
You can use RowEnter event
    Private Sub DataGridView1_RowEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.RowEnter
        ' your code
    End Sub

Open in new window

0
 
aaronthamAuthor Commented:
RowEnter event will fire when form load

any other event which only fire when select?
0
 
Jorge PaulinoIT Pro/DeveloperCommented:

It will fire on all. You can use a boolean variable that you set to true in the form load (before fill the grid) and to false after fill the grid. Then you just need to check if the variable is true or false before use that event.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
CodeCruiserCommented:
I think SelectionChanged is better suited especially if multiselect is false.
0
 
Jorge PaulinoIT Pro/DeveloperCommented:
Hi CodeCruiser,
The only problem with SelectionChanged event is if you select another cell in the same row it will trigger again the update in the second datagridview.
0
 
CodeCruiserCommented:
A simple PreviousSelectionIndex variable would help us in this situation. It would not be as useful then as i thought compared to the RowEnter method.
0
 
aaronthamAuthor Commented:
Hi CodeCruiser,

can provide some vb.net 2008 sample code?
0
 
Jorge PaulinoIT Pro/DeveloperCommented:
Have you tried RowEnter event ? What's the problem ?
You can do something like this:

    Private loadComplete As Boolean = False
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.DGVTableAdapter.Fill(Me.DGVDataSet.TableName)
    End Sub
 
    Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
        loadComplete = True
    End Sub
 
    Private Sub DataGridView1_RowEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.RowEnter
        If loadComplete Then
            Debug.WriteLine(Now & " RowEnter")
        End If
    End Sub

Open in new window

0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 4
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now