vb.net winform 2008 datagrid doubleclick event not firing - vb.net

i have a databound datagrid in vb.net 2008. This is a program where i use the double click event multipal times.. but for some reason on a new form it's not working anymore. In code behind i selected the datagrid and double click event. when i double click on teh grid in debug mode, it never fires off the event(i put a breakpoint in). I've tried several other events and none of them are firing.
Here is what the event look like
Private Sub dgWho2_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgWho2.DoubleClick
End Sub
and here is what it looks like for one that is working on another form
Private Sub dgQueryStats_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgQueryStats.DoubleClick
For Each O As asr.QueryStat In Os
If O.RowID = CInt(Me.dgQueryStats.Tag.ToString) Then
Me.lblQuery.Text = O.Text
End If
Next
Me.cmdCopyQuery.Visible = True
End Sub
in comparing the properties of the two datagrid, other than the name and the binding, they look the same as well. wondering if anyone has an idea.
thanks
shannon

Err... found my problem.. i had a datagrid.enabled=false stuck down in some code...
Sorry about that
shannon

Related

How to detect changes to a bound data

Winforms App - VB.Net 4.6.1
I have a data table that I fill when my form loads as follows:
Private Sub OnFormLoad(sender As Object, e As EventArgs) Handles MyBase.Load
Me.ApGetMratesListTableAdapter.Fill(Me.DsMRatesList.apGetMratesList)
End Sub
On the form I have textbox bound (Me.ApGetMratesListBindingSource) to a field in this datatable . I want to catch some sort of "RowChanged" event when the value in the textbox changes so I can set a "dirty" flag. Unfortunately after an hour of Googling and reading page after page with no examples of how to write the method I'm asking for help. Basically I cannot figure out how to refer to the event i.e. the part after HANDLES.
Private Sub SetDirty(ByVal sender As System.Object,
ByVal e As DataRowChangeEventArgs) Handles ?
m_IsDirty = True
End Sub
I've experimented until I ran out of options. If anyone can clue me as to how to write the event for the above Sub I'd be very grateful. If the signature isn't correct please clue me on that as well. Thank you!

How to write a single click event in Visual Basic?

I have created a form that allow users to close a form by clicking anywhere on the enlarged picture form (There are 3 objects to consider) and go back to the other form, which is called: "frmPhone". There's an actual picture on the form: "frmPhonePics" which is what I'm using to accomplish what I'm trying to do (was unable to insert an image on here. Sorry.) What I want to do is write a single click event to close the large picture form to allow the user to close it absolutely anywhere in the form, but I don't know how to do that. Here's the code I have so far:
Private Sub frmPhonePics_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Click
frmPhone.Show()
Me.Hide()
End Sub
It sounds as though you have a picture on your frmPhonePics form. If you double click that (from the VBA editor), you should be taken to the code - for example, you might see
Private Sub Image1_Click()
End Sub
Now all you have to do is add your code there:
Private Sub Image1_Click()
Me.Hide
frmPhone.Show()
End Sub
Note - the order matters, since frmPhone.Show() will "hijack" the code flow until it's dismissed, and in your code Me.Hide will not execute (so the form will not close) until frmPhone has been dismissed.
You can map the click handler for various object to one thing, if that is what you are asking:
Private Sub frmPhonePics_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Click, Handles picLarge.Click, Handles otherThing.Click
frmPhone.Show()
Me.Hide() ' should be Me.Close?
End Sub
Not sure why it is MyBase.Click in your code instead of Me.Click. Is this a subclassed form?
I'd strongly suggest using a DoubleClick instead of a single Click. The chances of an errant click doing the wrong thing is very great.
The easiest way is right from the designer. Write the sub routine, then for each control, in the properties window, click the events icon(thunderbolt) and assign the sub routine to the double-click event.
Alternatively, dispense with the Handles clause completely and use a series of Addhandler statements in the Load event handler. If you put a unique string in the names of the controls or if it's all the controls, you can iterate through the controls and use one addhandler statement for all of them
For Each c As Control In Me.Controls
AddHandler c.DoubleClick, AddressOf Ctrl_DoubleClick
Next
Private Sub Ctrl_DoubleClick(sender As Object, e As EventArgs)
'Do stuff
End Sub

Refresh dgv works only with the activated event, why?

I have two forms both with a dgv connected to two different datasets. When i change my data in one of the datasets i have to refresh the other one (i know the solution is not the best). After trying many many different ways of rebinding, refreshing and so i found the following code working:
Private Sub View_Activated(byval sender as Object, _ Byval e as
System.Eventargs) Handels MyBase.Activated Table_Load(Nothing,
Nothing) End Sub
Private Sub View_Load(byval sender as Object, _ byval e as
system.eventargs) Handels Mybase.Load
Me.TableAdapter.Fill(Me.Dataset.Table) End Sub
After Chaning things in dgv1 i can see the changes in dgv2 with these commands. BUT when i change mybase.activated to mybase.shown or something else it is not working anymore. Apparently this only works when i use the event activated, but i have no idea why?
BTW. I totally dont understand why the dgv is updated with the new data when i have my activated-event but when i comment the activated-event out the dgv is not updated.
The form's Activated event fires when the form window gets focus. The Load event only fires when the form is initially loaded.
When you make a change on one form, and change focus to the second form, Activated fires.

Windows form closing automatically when parent window gets focus

VB Windows form Application.. I am developing an application of which part of the program is around configuration settings allowing the user to enter configuration items. When the menubar item for configuration menu is clicked on the main form the menu opens. This is fine but the mainform should not become active again until the configuration menu has closed. This does not happen right now and the mainform simply comes to the foreground and the configuration form goes to the background... I realize that coding an event on the Child form to handle this would not work because the child window loses control and the main form gains control.. I thought of coding a function as follows on the main form but it does not seem logical because i would have to add to it for everyform and do checking to make sure the child is actually open before trying to close it..
Private Sub Form1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.GotFocus
MailSettingsWindow.Close()
RentalSettingsWindow.Close()
End Sub
I did away with the above sub routine and used the below code as per the recomendation of using showdialog which works just as i was looking for.
Private Sub MailingAndEmailSettingsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MailingAndEmailSettingsToolStripMenuItem.Click
Dim MailConfig As New MailSettingsWindow()
MailSettingsWindow.Showdialog()
End Sub
I did away with the above sub routine and used the below code as per the recommendation of using ShowDialog which works just as I was looking for.
My code is as follows:
Private Sub MailingAndEmailSettingsMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles MailingAndEmailSettingsMenuItem.Click
Dim MailConfig As New MailSettingsWindow()
MailSettingsWindow.ShowDialog()
End Sub

how to focus a specific textbox in vb.net

I'm making a desktop application in vb.net. When I click the back button (placed by me) on any form it hides current form and shows previous form but when i go again to the form from which i had hit back button then the focus cue still remains on the back button but I want the focus to be on the first textbox on that form or any specific button on which I want.....How can i achieve this...
I have already used some code to shift focus from one textbox to another when i press enter key...but it doesn't work in the above mentioned case....I'm using vb.net in visual studio 2005...
This is the code i'm using for shifting focus among textboxes
Private Sub party_code_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles party_code.KeyDown
If e.KeyData = Keys.Return Then
party_name.Focus()
End If
End Sub
Can anyone help me on this????
You need to add a handler for either the form's Activated event:
Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
party_name.Focus()
End Sub