[RESOLVED] [2008] How to send DateTimePicker value to TextBoxes?
Hi…:)
I have a table with 4 rows & 3 columns all contain textboxes
I want know what the codes to transfer DateTimePicker value by clicking a button to TextBoxes after selecting it from comboboxes
Regards...:wave:
Re: [2008] How to send DateTimePicker value to TextBoxes?
I dont use WinRar so cant say (most use winzip).
Is this an ASP.NET webproject?
Re: [2008] How to send DateTimePicker value to TextBoxes?
In the button.click event handler, you simply set the text property of the textbox of your choice to display the date. Something like this
Code:
Private Sub Button1_Click(Byval sender as Object, ByVal e As System.EventArgs)....
Me.TextBox1.Text = Me.DateTimePicker1.Value.ToString()
End Sub
Re: [2008] How to send DateTimePicker value to TextBoxes?
Quote:
Originally Posted by RobDog888
I dont use WinRar so cant say (most use winzip).
Is this an ASP.NET webproject?
it's vb.net form
Re: [2008] How to send DateTimePicker value to TextBoxes?
Quote:
Originally Posted by RobDog888
I dont use WinRar so cant say (most use winzip).
Is this an ASP.NET webproject?
Actually, I found WinRar is way better than Winzip. So it's about time to pitch Winzip and get WinRar now, Rob :)
Re: [2008] How to send DateTimePicker value to TextBoxes?
Quote:
Originally Posted by stanav
In the button.click event handler, you simply set the text property of the textbox of your choice to display the date. Something like this
Code:
Private Sub Button1_Click(Byval sender as Object, ByVal e As System.EventArgs)....
Me.TextBox1.Text = Me.DateTimePicker1.Value.ToString()
End Sub
Thanks for reply...:)
The codes working , but i wanted it with comboboxes approach codes ...
Re: [2008] How to send DateTimePicker value to TextBoxes?
Quote:
Originally Posted by HOTFIX
Thanks for reply...:)
The codes working , but i wanted it with comboboxes approach codes ...
What exactly is "comboboxes approach"? Care to explain? I'm not downloading your project just to take a look...
Re: [2008] How to send DateTimePicker value to TextBoxes?
Quote:
Originally Posted by stanav
What exactly is "comboboxes approach"? Care to explain? I'm not downloading your project just to take a look...
I have include an image to my 1st topic could U PLZ check it .
THANKS
Re: [2008] How to send DateTimePicker value to TextBoxes?
I've looked at the picture and still could not figure out what you mean by saying "comboboxes approach".
If you mean to display the date in a textbox with the same format as it is displayed in the datetimepicker then it's just a matter of supplying the Date.ToString method with the custom format of your choice.
Re: [2008] How to send DateTimePicker value to TextBoxes?
Quote:
Originally Posted by stanav
I've looked at the picture and still could not figure out what you mean by saying "comboboxes approach".
If you mean to display the date in a textbox with the same format as it is displayed in the datetimepicker then it's just a matter of supplying the Date.ToString method with the custom format of your choice.
I mean when I select “A” from combox1 & select “1”from combobox2 the DateTimePicker Value will transfer to correct cell in the table
Re: [2008] How to send DateTimePicker value to TextBoxes?
OK, simplest way to do this is to put all of your textboxes in a 2-d array, then you can refer to them using the array indices.
In your picture, I see that you have 2 columns and 3 rows of textboxes. The 1st combobox indicates the column number and the 2nd combobox gives the row number, is that right?
If that's the case, you simply do this:
Code:
'Declare a class level 2-d textbox array
Private myTextBoxes(,) As TextBox
'Then in the form load event handler, you populate the textbox array
Private Sub Form1_Load(Byval......) Handles MyBase.Load
myTextBoxes = New TextBox(,) {{TextBox1, TextBox3, TextBox5}, {TextBox2, TextBox4, TextBox6}}
End Sub
'And finally in the button click event handler, you do
Dim column As Integer = ComboBox1.SelectedIndex
Dim row As Integer = comboBox2.SelectedIndex
If row > -1 AndAlso column > -1 Then
myTextBoxes(row, column).Text = DateTimePicvker1.Value.ToString()
End If
Re: [2008] How to send DateTimePicker value to TextBoxes?
Quote:
Originally Posted by stanav
OK, simplest way to do this is to put all of your textboxes in a 2-d array, then you can refer to them using the array indices.
In your picture, I see that you have 2 columns and 3 rows of textboxes. The 1st combobox indicates the column number and the 2nd combobox gives the row number, is that right?
If that's the case, you simply do this:
Code:
'Declare a class level 2-d textbox array
Private myTextBoxes(,) As TextBox
'Then in the form load event handler, you populate the textbox array
Private Sub Form1_Load(Byval......) Handles MyBase.Load
myTextBoxes = New TextBox(,) {{TextBox1, TextBox3, TextBox5}, {TextBox2, TextBox4, TextBox6}}
End Sub
'And finally in the button click event handler, you do
Dim column As Integer = ComboBox1.SelectedIndex
Dim row As Integer = comboBox2.SelectedIndex
If row > -1 AndAlso column > -1 Then
myTextBoxes(row, column).Text = DateTimePicvker1.Value.ToString()
End If
Hi stanav...
I put your suggested code:
Code:
Public Class Form1
Private myTextBoxes(,) As TextBox
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim column As Integer = ComboBox1.SelectedIndex
Dim row As Integer = ComboBox2.SelectedIndex
If row > -1 AndAlso column > -1 Then
myTextBoxes(row, column).Text = DateTimePicker1.Value.ToString()
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
myTextBoxes = New TextBox(,) {{TextBox1, TextBox3, TextBox5}, {TextBox2, TextBox4, TextBox6}}
End Sub
End Class
It working only for Cells A:1 & A:2
The rest cells I get errors and incorrect DateTimePicker values position.
Note:ComboBox1(columns A,B) & ComboBox2(rows 1,2,3)
A:1= TextBox1
A:2= TextBox2
A:3= TextBox3
B:1= TextBox4
B:2= TextBox5
B:3= TextBox6
Re: [2008] How to send DateTimePicker value to TextBoxes?
That means you need to put the TextBoxes to the array in the right order.
Change this line in the Form.Load event handler
Code:
myTextBoxes = New TextBox(,) {{TextBox1, TextBox3, TextBox5}, {TextBox2, TextBox4, TextBox6}}
To this and you should be all set.
Code:
myTextBoxes = New TextBox(,) {{TextBox1, TextBox2, TextBox3}, {TextBox4, TextBox5, TextBox6}}
Re: [2008] How to send DateTimePicker value to TextBoxes?
Thanks for reply...:)
I still have same problems of errors and incorrect positions...:cry:
Any idea..:confused:
Re: [2008] How to send DateTimePicker value to TextBoxes?
Hi,
I know it isn't the best way, but it's working:
vb Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If ComboBox1.SelectedItem = ("A") And ComboBox2.SelectedItem = ("1") Then
TextBox1.Text = DateTimePicker1.Value.ToString
End If
If ComboBox1.SelectedItem = ("A") And ComboBox2.SelectedItem = ("2") Then
TextBox2.Text = DateTimePicker1.Value.ToString
End If
If ComboBox1.SelectedItem = ("A") And ComboBox2.SelectedItem = ("3") Then
TextBox3.Text = DateTimePicker1.Value.ToString
End If
If ComboBox1.SelectedItem = ("B") And ComboBox2.SelectedItem = ("4") Then
TextBox4.Text = DateTimePicker1.Value.ToString
End If
If ComboBox1.SelectedItem = ("B") And ComboBox2.SelectedItem = ("5") Then
TextBox5.Text = DateTimePicker1.Value.ToString
End If
If ComboBox1.SelectedItem = ("B") And ComboBox2.SelectedItem = ("6") Then
TextBox6.Text = DateTimePicker1.Value.ToString
End If
End Sub
Hope it helps,
sparrow1
Re: [2008] How to send DateTimePicker value to TextBoxes?
Quote:
Originally Posted by HOTFIX
Thanks for reply...:)
I still have same problems of errors and incorrect positions...:cry:
Any idea..:confused:
What errors? What incorrect positions? Saying that your program is having errors without providing what the errors are is not a way to start trouble shooting/debugging.
Besides, the code I gave you should give you enough that you can see the logic to achieve what you need. You should be able to adjust it so that it works the way you want. Don't just copy sample code into your program and expect it to work as is...
Re: [2008] How to send DateTimePicker value to TextBoxes?
Quote:
Originally Posted by sparrow1
Hi,
I know it isn't the best way, but it's working:
vb Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If ComboBox1.SelectedItem = ("A") And ComboBox2.SelectedItem = ("1") Then
TextBox1.Text = DateTimePicker1.Value.ToString
End If
If ComboBox1.SelectedItem = ("A") And ComboBox2.SelectedItem = ("2") Then
TextBox2.Text = DateTimePicker1.Value.ToString
End If
If ComboBox1.SelectedItem = ("A") And ComboBox2.SelectedItem = ("3") Then
TextBox3.Text = DateTimePicker1.Value.ToString
End If
If ComboBox1.SelectedItem = ("B") And ComboBox2.SelectedItem = ("4") Then
TextBox4.Text = DateTimePicker1.Value.ToString
End If
If ComboBox1.SelectedItem = ("B") And ComboBox2.SelectedItem = ("5") Then
TextBox5.Text = DateTimePicker1.Value.ToString
End If
If ComboBox1.SelectedItem = ("B") And ComboBox2.SelectedItem = ("6") Then
TextBox6.Text = DateTimePicker1.Value.ToString
End If
End Sub
Hope it helps,
sparrow1
Many Thanks "sparrow1" this way of codes is working great, although there are many lines...:thumb:
Regrads...:wave:
Re: [2008] How to send DateTimePicker value to TextBoxes?
sparrow's code could have been shorter with select case
Code:
Select Case ComboBox1.SelectedItem.ToString & ComboBox2.SelectedItem.ToString
Case "A1"
Case "A2"
End Select
Re: [2008] How to send DateTimePicker value to TextBoxes?
Quote:
Originally Posted by stanav
What errors? What incorrect positions? Saying that your program is having errors without providing what the errors are is not a way to start trouble shooting/debugging.
Besides, the code I gave you should give you enough that you can see the logic to achieve what you need. You should be able to adjust it so that it works the way you want. Don't just copy sample code into your program and expect it to work as is...
Hi stanav..:)
Sorry for not giving enough details about the errors because I assumed you have run the application on your pc and having same errors…
I really try to work logically how the codes are working that why I give you the note of textbox locations in the table “A:1=Textbox1,A:2=Textbox2…etc” because I have tried swapping the Textboxes in line coding “{{TextBox1, TextBox2, TextBox3}, {TextBox4, TextBox5, TextBox6}}”
And I even tried to change numeric value in code line “If row > -1 AndAlso column > -1 Then”.
Please note: my level in VB.NET is beginner and the English language is not my first language so please excuse me.
Anyway I appreciate your help …:thumb:
Best Regards… :wave:
Re: [2008] How to send DateTimePicker value to TextBoxes?
Quote:
Originally Posted by dbasnett
sparrow's code could have been shorter with select case
Code:
Select Case ComboBox1.SelectedItem.ToString & ComboBox2.SelectedItem.ToString
Case "A1"
Case "A2"
End Select
Hi dbasnett …
Thanks for advice; I’ll try to use this method...
Regards…