I am new to VB and .NET, and I am trying to display a message box when the user double clicks on a data grid, to display selected data.
Normally I can just use MessageBox("Hello")
from windows control with the button click event.
But when I type MessageBox("Hello") from datagridview's double click event, I get a compile error
'MessageBox' is a class type and cannot be used as an expression.
I also tried to create a second blank form on visual studio, on button click event I typed in: Form2.Show()
, and I did the same on datagridview double click event.
When I click the button Form2 is displayed but when I double click on datagridview, Form2 is not displayed.
Any reason why datagridview control behave differently than other windows control?, and what is the best and easy way to display pop-up windows or display 2nd form when user double click on datagridview?
What I am trying to do is when the user double clicks on datagridview, I would like to create a pop-up form, and fill in some of the data from selected datagridview row on the pop-up form.
I am not sure how to reply to Alex suggestion, I try to add comment but it says more than 125 characters and I could not find button to reply the thread, so I just put it here. (let me know if there is better way to do this instead of keep adding to my questions).
Hi Alex,
this is the code that I have on form1 class, form2 class is just a simple blank form, I just create add new form right click add form from Visual Studio. After I click the button form2 is pop up then I close it Form2, then double click datagridview cell, nothing happen, the I click the button form2 is pop up.
Thank you.
Public Class Form1 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load 'TODO: This line of code loads data into the 'TestDB1DataSet.t_emp' table. You can move, or remove it, as needed. Me.T_empTableAdapter.Fill(Me.TestDB1DataSet.t_emp)
End Sub
Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
' put some code here
Form2.Show()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Form2.Show()
End Sub
End Class
MessageBox
is is a type. Use the.Show()
method:MessageBox.Show(...)
– Ňɏssa PøngjǣrdenlarpMsgBox("Hello")
instead – SSS