Im using Visual Basic 2008
I have 2 forms
Main, EditCustomerInfo
Main form contains the following
Public Class Main
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
EditCustomerInfo.ShowDialog()
End Sub
EditCustomerInfo contains a text box and the following
Public Class EditCustomerInfo
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Not CustomerIDTextBox.Text = "" Then
Me.Close()
Else : Me.Hide()
End If
End Sub
WHAT IT DOES:
So with this code alone when i debug the program it takes me to the main form and allows me to click a button to open the editcustomerinfo form
When im on the editcustomerinfo form i have a textbox and a button. If something is typed in the textbox and the button is clicked then the form hides, if nothing is typed in the textbox when the button is clicked then the form closes.
WHAT I WOULD LIKE IT TO DO:
If something is typed in the textbox i would like the button on the editcustomerinfoform to hide the editcustomerinfoform and also create a button on main form that allows the user to bring the editcustomerinfo form back up with what was typed in the text box.
Suggestions?
Automatic behavior, such as this, always worries me. How do you know when a user has completed their input without a lost focus event. If there are no other controls on the screen, then users won't readily know how to trigger the event. That being said, you can use a timer to delay the screen closing from a KeyPress event.
Public Class EditCustomerInfo
Private WithEvents userInputDelay As Timer = New Timer() With {.Interval = 1000} REM 1 second delay for next user input
Public ReadOnly Property CustomerId As String
Get
Return CustomerIDTextBox.Text
End Get
End Property
Private Sub CustomerIDTextBox_KeyPress(sender As Object, e As KeyPressEventArgs) Handles CustomerIDTextBox.KeyPress
userInputDelay.Enabled = False
REM Reset the timer
userInputDelay.Enabled = True
End Sub
Private Sub userInputDelay_Tick(sender As Object, e As KeyPressEventArgs) Handles userInputDelay.Tick
If Not CustomerIDTextBox.Text = "" Then
Me.Close()
Else : Me.Hide()
End If
End Sub
End Class
Add a button (Button2) to your Main. The code below will hide Button1 when the EditCustomerInfo.Textbox1.Text value is null/blank/white space. Button2's visibility is always the inverse of Button1.
Private EditCustomerInfoInstance As New EditCustomerInfo
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
EditCustomerInfoInstance.ShowDialog()
Button1.Visible = String.IsNullOrWhiteSpace(EditCustomerInfoInstance.CustomerId)
End Sub
Private Sub Button1_VisibleChanged(sender As Object, e As EventArgs) Handles Button1.VisibleChanged
Button2.Visible = Not Button1.Visible
End Sub
Related
I need to use "Show()" method for dialog winform using Ironpython
and i need to get result of button pressing and use it in another part of program
how can i wait for pressing OK in modal "Show()" dialog?
mform = Form3()
mform.Show()
# How to wait for button OK
Thx
Use ShowDialog() instead of Show().
Then check "if (mform.DialogResult == DialogResult.OK)"
Suppose you have a main form called Form1 and a secondary form called AddForm which presents some result when the [OK] button is pressed.
The main form then can subscribe to the FormClosed event of the secondary form and pull the result if the user clicked on the [OK] button.
This can all happen in the subroutine where the secondary form is shown
Private Sub Button1.Click(sender as Object, e as EventArgs) Handles Button1.Click
Dim dlg as New AddForm
AddHandler dlg.FormClosed, _
Sub(e,ev) TextBox1.Text = If(dlg.DialogResult = DialogResult.OK, dlg.Result, String.Empty)
dlg.Show()
End Sub
And in the secondary form make sure there is a property called Result which contains the results
The [OK] button has a handler like so
Private Sub Button1_Click(sender as Object, e as EventArgs) Handles Button1.Click
Result = ...
DialogResult = DialogResult.OK
Me.Close()
End Sub
and the [Cancel] button has a handler as so
Private Sub Button2_Click(sender as Object, e as EventArgs) Handles Button2.Click
DialogResult = DialogResult.Cancel
Me.Close()
End Sub
I have two of the simplest forms, with a couple of Buttons and a TextBox. I click to open the second form (frmModal) using ShowDialog(), type some text into txtGreeting and press the Yes button. What should happen is that a MessageBox appears confirming the text that was entered into txtGreeting, but it is empty.
I understand that the Form's properties should be accessible until the form goes out of scope, but they disappear straight-away. I can't even read dialog.txtGreeting.Text.
Am I missing anything obvious please?
Public Class frmMain
Private Sub btnModal_Click(sender As Object, e As EventArgs) Handles btnModal.Click
Dim dialog As frmModal
dialog = New frmModal()
Dim result As DialogResult = frmModal.ShowDialog(Me)
If result = Windows.Forms.DialogResult.Yes Then
MessageBox.Show(dialog.Greeting)
End If
'dialog.Dispose()
End Sub
End Class
Public Class frmModal
Public Property Greeting As String
Get
Return txtGreeting.Text
End Get
Set(value As String)
End Set
End Property
Private Sub btnYes_Click(sender As Object, e As EventArgs) Handles btnYes.Click
MessageBox.Show(Greeting)
End Sub
End Class
The Yes button has it's DialogResult property set to Yes.
I've tried moving the dialog-declaration out of the click-event, using an (unnecessary) Dispose(), deliberately assigning the Greeting property in the Yes-click event..
You're effectively instantiating the form twice. By showing frmModal with ShowDialog and then asking for the Greeting value on the instance you created, named 'dialog'.
This should fix it.
Private Sub ModalTestButton_Click(sender As System.Object, e As System.EventArgs) Handles ModalTestButton.Click
Dim dialog As frmModal
dialog = New frmModal()
Dim result As DialogResult = dialog.ShowDialog(Me)
If result = Windows.Forms.DialogResult.Yes Then
MessageBox.Show(dialog.Greeting)
End If
End Sub
In form i created three dynamic Gridview , I want to perform some specific operations on selection of particular Gridview, can any one help me how to know which gridview got seletec?
There is a .GotFocus() event on the DataGridView you can use to store something in a form scope (or global) variable. (sorry for the VB...)
Dim LastGirdWithFocus As String = ""
Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
MsgBox(LastGirdWithFocus)
End Sub
Private Sub dgv1_GotFocus(sender As Object, e As System.EventArgs) _
Handles dgv1.GotFocus, dgv2.GotFocus
LastGirdWithFocus = sender.name
End Sub
I would like to make back and forward button in my app in WPF (Visual Basic 2010 Express). I have six tabitems and this two buttons will be used to navigate between tabitems.
I have used following code, but it doesn't work. what am I doing wrong?
Public ReadOnly Property CanGoForward As Boolean
Get
CanGoForward = True
End Get
End Property
Private Sub forward_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles forward.Click
TabIdentiPodatki.goforward()
End Sub
Private Sub TabIdentiPodatki_CanGoForwardChanged(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles forward.CanGoForwardChanged
forward.IsEnabled = TabIdentiPodatki.cangoforward
End Sub
im new to wpf, so please bear with me
i made a window for the purpose of managing "profile" records
while the navigation and updating is working
i cannot seem to get insertion working, as well
heres the very simple code
Imports System.Collections.ObjectModel
Public Class Window1
Dim WindowEntities As New DataEntities
Dim WindowList As ObservableCollection(Of Profile)
Function ProfilesViewSource() As CollectionViewSource
Return CType(FindResource("ProfilesViewSource"), CollectionViewSource)
End Function
Function DefaultView() As CollectionView
Return CollectionViewSource.GetDefaultView(ProfilesViewSource.View)
End Function
Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs) Handles MyBase.Loaded
WindowList = New ObservableCollection(Of Profile)(From x In WindowEntities.Profiles Order By x.ProfileName)
ProfilesViewSource.Source = WindowList
End Sub
Private Sub btnSave_Click(ByVal sender As Object, ByVal e As RoutedEventArgs) Handles btnSave.Click
WindowEntities.SaveChanges()
End Sub
Private Sub btnAdd_Click(ByVal sender As Object, ByVal e As RoutedEventArgs) Handles btnAdd.Click
WindowList.Add(New Profile)
DefaultView.MoveCurrentToLast()
End Sub
Private Sub btnNext_Click(ByVal sender As Object, ByVal e As RoutedEventArgs) Handles btnNext.Click
DefaultView.MoveCurrentToNext()
End Sub
End Class
when i press add, i get a new empty record, when i fill it in, i see that the collection sees it, as there is an onform listbox showing the profiles, and it gets listed there, so its actually attached to the list, but the savechanges command does not insert it into the db
there may be some validation errors upon insert, but then i would get some indication, right? now its just silently failing. as if i never tied to commit changes
thank you very much for your help fellows
(by IVerzin)
1. create new Profile.
2. Add it to WindowEntities
3. Add it to WindowList