Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Problem Calling a Function from another Function

Avatar of Mr_Fulano
Mr_FulanoFlag for United States of America asked on
Visual Basic.NET
4 Comments1 Solution206 ViewsLast Modified:
Hi, I have a VB 2005 Windows Form and I have the following two blocks of code within my Form.


[Block 1:] (dgv is a DataGridView)   -- This code creates a handler for a Function and the Function retrieves some values from cells within a DataGridView.

AddHandler dgv.CellEnter, AddressOf dgv_CellEnter
'
Private Sub dgv_CellEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs)
        '
        lblEventNo.Text = "Event No:  " & Trim((dgv.Item(0, e.RowIndex).Value))
        lblEventDate.Text = "Event Date/Time:  " & Trim((dgv.Item(3, e.RowIndex).Value))
        lblEventType.Text = "Event Type:  " & Trim((dgv.Item(2, e.RowIndex).Value))
        tbxEventDescription.Text = Trim((dgv.Item(4, e.RowIndex).Value))
End Sub

[Block 2:] This block creates TabPages in a TabControl and each TabPage contains a DataGridView. The code also creates a handler for the CLICK event of the TabPages.

Dim tp As New TabPage
tp.Controls.Add(dgv)
tp.Text = sFileName
tp.Name = sFileName
TabControl1.Controls.Add(tp)
AddHandler tp.Click, AddressOf tp_click
'
'
Private Sub tp_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
        'Console.WriteLine(TabControl1.SelectedTab.Text.ToString)
End Sub

===========

Both blocks of code work fine.  However, I need to call the Function "dgv_CellEnter" from the " tp_click" Function when the TapPages are clicked, so that I can update the values for  lblEventNo.Text, lblEventDate.Text ,  lblEventType.Text , and  tbxEventDescription.Text.

I'm having problems calling one Function from the other Function. Is there a way to do this? I tried calling it using:

dgv_CellEnter( dgv, ???) , but I do not know what to use for "(System.Windows.Forms.DataGridViewCellEventArgs)"

Note: I would like the "SelectedCells" or Row to be Row Index = 0 each time the Selected TabPage changes.

Can someone help?

Thanks.
Fulano