I am using Visual Basic 2010.
I have create a simple Textbox which can take multiline input with three buttons clear Text,Date and Show Message.
Assuming the TextBox contains some text.
I want to clear the textbox by clicking "Clear Text" button.
Button1 is the name of the control "Clear Text"
here is the code i used.
Private Sub Button1_Click()
Button1.Text = ""
End Sub
But when i start debugging and click "Clear Text" instead of Textbox getting Cleared the "Clear Text" Control button itself gets Cleared.
Thankyou
because you are clearing the text from button1.
replace Button1.Text = ""
with textbox1.text=""
(textbox1 or the real name of your text box control...)
You can also use the Clear() method:
Clears all the content from the text box.
So that would look like:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
TextBox1.Clear()
End Sub
Related
i have a Textbox in vb.net and have assigned to it autocomplete data , when i enter the first letter of the word it shows a suggestions but when i choose one and click tab to complete the word it goes to next text box
for example :
i have put these suggestion as a source for the textbox
GigabitEthernet
but i want to complete it with a number , so i have to click tab and complete
i have tried all types of auto complete with no luck
is it doable to complete the word when i click in tab without going to the next box?
Try this code
Private Sub TextBox1_PreviewKeyDown(sender As Object, e As PreviewKeyDownEventArgs) Handles TextBox1.PreviewKeyDown
If e.KeyCode = Keys.Tab Then e.IsInputKey = True
End Sub
if somebody can help me in VB coding to show required field to be mandatory when I click save Button and the function of saving should not be work till all required field to be filled
(please visual basic codes not other )
You can use a simple If function that occurs when the button is pressed.
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
If TextBox1.Text = "" Or TextBox2.Text = "" Then
Msgbox("A field is missing")
Exit Sub 'To avoid saving, escape the procedure
Else
' code to save goes here
End If
End Sub
Here, I assume that TextBox1 and TextBox2 are the fields you want and Button1 is the save button.
I have a few textboxes that will require user input, and I want to add something that the user can revert to in case they forgot the proper syntax required for input.
For example, if in textbox1 the input MUST ALWAYS be something like "bSAMPLE" or "bSAMPLE2" I want to show the user (i.e., bSAMPLE) so that they may see the proper syntax required.
I know I can add a button and show a messagebox, but that just seems too much for something this simple, as for a tooltip, I'm not sure if the user might hover long enough to see the example. Any tips?
Did a quick test on some code for the tooltip method, and this works for me:
'In your form's general declarations:
Dim tt As New ToolTip
Private Sub TextBox_Enter(sender As Object, e As EventArgs) Handles TextBox1.Enter, TextBox2.Enter 'list out all your text boxes here
Dim txtbx As TextBox = sender, dispText As String
Select Case txtbx.Name
Case TextBox1.Name
dispText = "How to use text box 1"
Case TextBox2.Name
dispText = "How to use text box 2"
'flesh out the text for each text box
End Select
tt.Show(dispText, txtbx)
End Sub
Private Sub TextBox_Leave(sender As Object, e As EventArgs) Handles TextBox1.Leave, TextBox2.Leave 'finish the list as above
tt.Hide()
End Sub
I want to be able to edit/delete/insert lines of text from a textfile by using listbox and textbox.
I want to display all the contents of the textfile per line in a listbox and when I click a line of text it will then display it in the textbox giving me the option to either edit or delete that line of text.
My insertion of text would be inserted after the last line of text being displayed in the listbox. Is this possible? I just want a starting point and I will continue it from there. Thanks in advance.
Here is an answer with a listview , button 9 is to fill Listview, listview click sends the text to textbox and button 10 saves it back to the listview
This is probably the simplest way to do what you want to achieve.
Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
ListView1.HeaderStyle = ColumnHeaderStyle.None
ListView1.HideSelection = False
For i As Integer = 0 To 50
ListView1.Items.Add("Line number" & i.ToString)
Next
End Sub
Private Sub ListView1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListView1.Click
TextBox8.Text = ListView1.SelectedItems(0).Text
End Sub
Private Sub Button10_Click(sender As Object, e As EventArgs) Handles Button10.Click
ListView1.SelectedItems(0).Text = TextBox8.Text
End Sub
Probably a good starting point for you anyway and expand this code from here on.
Yes. It is possible. I would suggest to use already existing text editors rather than re-inventing the wheel. If you still want to go ahead and create a new one from start, then you can try the following.
Create a window form application in vb.net with ListBox control for showing the lines, a textbox control for entering the file name, a button to browse to the given file, a button on clicking on which the file content should get loaded. Refer file objects for this.
Utilise ContextMenu class in vb.net to allow right click to read selected listbox line and accordingly perform add/delete/edit operation by modifying the selected listitem value.
I have a datagridview with a menustrip. I want to give the user a message that he has to save when he leaves the datagridview and made any changes in there. What i tried:
Private Sub DGV_validated(sender As Object, e As EventArgs) Handles DGV.validated
If DataSet1.table.GetChanges IsNot Nothing Then
MsgBox("You made changes please press the save button!")
End If
End Sub
I tried that with the leave, validated and lostfocus event but the msgbox pops up not until i am on another form after pressing something in the menustrip.
I just made a forms project with a DataGridView on the form and put this in the code behind and it worked without issue:
Private Sub DataGridView1_MouseLeave(sender As Object, e As System.EventArgs) Handles DataGridView1.MouseLeave
MsgBox("hi")
End Sub
Basically, after the cursor leaves the DataGridView, the MsgBox will pop up. Is that what you were looking for? This was done in Visual Studio 2010.