Saving Multiple Times of Day in TextBox - Visual Basic - vb.net

I'm having trouble figuring out how to save the time of day to a text box. The time of day is generated on a click, and I would like it to add it to the list every time I click, while keeping the older values in the list. I know how to make a list from list a list box, but I need to copy and paste the times from the box into excel. (And if I haven't asked enough already, how to format those times to be used in Excel)
To generate the time, I'm using
Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Timer1.Start()
TextBox1.Text = Date.Now.ToString("hh:mm:ss")

You can use a ListBox
On button click event do
ListBox1.Items.Add(DateTime.Now.ToString()
But it you have to use text box
Then use ' +=' operator
TextBox1.text += DateTime.Now.ToString()

Related

Search data inside Datagridview without database - VB.net

I've searched around and couldn't find the one I've been looking for.
I have a DataGridView in VB.NET with thousands of records from MySQL Database. Now, I want to SEARCH item_description that matches or something LIKE the inputted text. I am using TEXTCHANGED
I didn't use search to database since its taking time to load.
Sample is
Search: orange
DataGridView must filter and display only with the words like "orange"
ITEM_ID
ITEM_DESCRIPTION
120
Orange Juice
832
Orange Fruit
I am thinking of getting the array list names of the column "item_description" and filter it but I don't know where to start and what codes to use. Thank you
Assuming that you have taken the advice in my comment and populated a DataTable and then bound that to the DataGridView via a BindingSource, filtering the data is a simple matter of setting the Filter property of that BindingSource. In your case, it should be something like this:
myBindingSource.Filter = "ITEM_DESCRIPTION LIKE 'orange*'"
One issue with filtering on the TextChanged event of a TextBox is that you will filter multiple times when the user types multiple characters when you only need the last one. To alleviate that, I suggest using a Timer that you start/restart each time a character is typed and then filter when it Ticks. That will enable the user to type multiple characters without filtering but also not have a significant wait after they stop typing for the filtering to be done. I recommend an interval of around 250 milliseconds but you can experiment to see what you think is best. E.g.
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
'Start/restart the Timer.
Timer1.Stop()
Timer1.Start()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Timer1.Stop()
'Perform the filtering.
BindingSource1.Filter = $"ColumnName LIKE '{TextBox1.Text}*'"
End Sub

Overload Clipboard.SetText VB.net 3.5 (or how to copy 3-4 text box conents at same time)

I have a form where I require user input and when the user presses the "generate" key it will copy all the data from the relevant text boxes to the clipboard for them to enter the data in an external application.
At the moment i can only find out how to get the function to copy one text box at a time, and not string them into a sentence.
Private Sub Notes_Click(sender As Object, e As EventArgs) Handles Notes.Click
My.Computer.Clipboard.SetText(TextBox1.Text, TextBox6.Text, TextBox5.Text, TextDataFormat.Text)
The problem is that the function can no be overloaded. Can someone please confirm the function i can use (or provide me a sample code) for how to copy all text box contents to the clipboard?
This is ALL on one form
The clipboard only accepts one text value at a time, so it's pretty clear why your overload won't work. If you need multiple values, concatenate them; if you need to keep them separately identifiable, put a separator character between them and parse them back out on the receiving end.
My.Computer.SetText(TextBox1.Text + TextBox2.Text + TextBox3.Text +...)

Textbox: missing first character typed on the TextBox

I have 2 text boxes to accept info but only one of them is need at the same time (One is for selection of the first letter and the other is for selection of any part of the name)
So I need to delete the text of the other textbox when the user start typing on the textbox
Something like this work:
Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
TextBox1.Text = ""
End Sub
But there's a problem, the first character the user type is not displayed, I think is because the first character typed is used to launch the event.
Example:
TextBox1.Text = "A"
when the user click on TextBox2 and type michael the "m" is lost
I don´t want to use the "GotFocus" event because a simple TAB pulsed to jump from TextBox1 to another control can delete the text on TextBox1 when the user stop on TextBox2, even if he don´t want to type anything there
How can I manage this mistake?
Right answer:
From #Plutonix
"No user is going to expect this behavior and you will go mad trying to divine when to execute and when not to. A better thing might be to select the text on the Enter event - at least that has been seen before by users"

All elements of an array cannot be accessed from a for loop in monthCalendar Control - Visual Basic

I have a bit of an issue here with the monthCalendar Control in Visual Basic. What is happening in the program is I have a calendar and a text box. The user selects a date on the calendar, then types in information into the textbox component, then presses the add button. From there the add button sets up a parallel array that contains the selected date and the added string from the text box as a way to add planner information for each date. Then the date is bolded for each time an addition like this has happened.
From there you are suppose to be able to click each bolded date and view the information you added. The issue is this only works on the last added date. For some reason it will only read the last element added to the array. I have the for loop down below. I do not understand why I cannot select any bolded date and view the text added. I have option strict on so I know no data loss is occurring. Also I know the date is being selected and placed into the string each time a date is selected on the calendar because I am displaying it onto a label each time. What is the problem. Is it some logical error I am not catching or is it something else?
Public Sub MonthCalendar1_DateChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MonthCalendar1.DateChanged
For index As Integer = 0 To intSizeOfSelectedDatesAry - 1
strSelectedDay = CStr(MonthCalendar1.SelectionRange.Start) ' place the selected date into a string
lblError.Text = strSelectedDay
lblError.Visible = True
Dim strAryDate As String = arySelectedDates(index)
If (arySelectedDates(index) = strSelectedDay) Then
lblInstructions.Text = strSelectedDay
lblSelectedDate.Text = aryTextForDates(index)
index = intSizeOfSelectedDatesAry - 1
End If
Next
End Sub

i am try exchange data between two textbox in vb.net using vs2010

I'm trying to change a textbox text dynamically from another textbox and When i'm writing in the first textbox, the text that i'm writing must appare in the second textbox. but here problem is that i have not contain id or name destination text box Please help!and i have work in vb.net using vs2010
Welcome to StackOverflow. I will assume you're a complete newbie and will try to be as comprehensive as possible.
Right click on the first text box and choose properties. Go to the first property: (Name). This will give you the name of that text box. Now do the same for the second text box. Now, double click on the first text box. You will see two dropdown lists on top of your code window. The one on the left stores controls like textbox, form, etc., and one on the right shows the properties of the control. Select second textbox name from the first dropdown list and select TextChanged from the second dropdown list. You will get something like this:
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
End Sub
Now add this to the above subroutine:
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
TextBox2.Text = TextBox1.Text
End Sub
I am assuming that your first textbox's name is TextBox1 and second textbox's name is TextBox2. These might be different in your code.
For more details about events, properties, and functions, I recommend you read this article: http://msdn.microsoft.com/en-us/library/ms172576(v=vs.90).aspx. That article is based on Visual Studio 2008 but it is equally applicable for Visual Studio 2010 as well. You will also find additional references and samples on the MSDN Visual Basic site: http://msdn.microsoft.com/en-us/library/vstudio/2x7h1hfk.aspx
Change TextBox1 and TextBox2 with the names of your textboxes:
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) _
Handles TextBox1.TextChanged
TextBox2.Text = TextBox1.Text
End Sub