Results 1 to 20 of 20

Thread: [RESOLVED] [2008] How to send DateTimePicker value to TextBoxes?

  1. #1

    Thread Starter
    Lively Member HOTFIX's Avatar
    Join Date
    Sep 2008
    Posts
    91

    Resolved [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...
    Last edited by HOTFIX; Dec 14th, 2008 at 12:51 PM.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    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
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  4. #4

    Thread Starter
    Lively Member HOTFIX's Avatar
    Join Date
    Sep 2008
    Posts
    91

    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

  5. #5
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    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
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  6. #6

    Thread Starter
    Lively Member HOTFIX's Avatar
    Join Date
    Sep 2008
    Posts
    91

    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 ...

  7. #7
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    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...
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  8. #8

    Thread Starter
    Lively Member HOTFIX's Avatar
    Join Date
    Sep 2008
    Posts
    91

    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

  9. #9
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    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.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  10. #10

    Thread Starter
    Lively Member HOTFIX's Avatar
    Join Date
    Sep 2008
    Posts
    91

    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

  11. #11
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    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
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  12. #12

    Thread Starter
    Lively Member HOTFIX's Avatar
    Join Date
    Sep 2008
    Posts
    91

    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

  13. #13
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    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}}
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  14. #14

    Thread Starter
    Lively Member HOTFIX's Avatar
    Join Date
    Sep 2008
    Posts
    91

    Re: [2008] How to send DateTimePicker value to TextBoxes?

    Thanks for reply...
    I still have same problems of errors and incorrect positions...
    Any idea..
    Last edited by HOTFIX; Oct 1st, 2008 at 11:33 AM.

  15. #15
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: [2008] How to send DateTimePicker value to TextBoxes?

    Hi,

    I know it isn't the best way, but it's working:

    vb Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.  
    3.         If ComboBox1.SelectedItem = ("A") And ComboBox2.SelectedItem = ("1") Then
    4.             TextBox1.Text = DateTimePicker1.Value.ToString
    5.  
    6.         End If
    7.         If ComboBox1.SelectedItem = ("A") And ComboBox2.SelectedItem = ("2") Then
    8.             TextBox2.Text = DateTimePicker1.Value.ToString
    9.        
    10.         End If
    11.         If ComboBox1.SelectedItem = ("A") And ComboBox2.SelectedItem = ("3") Then
    12.             TextBox3.Text = DateTimePicker1.Value.ToString
    13.      
    14.         End If
    15.  
    16.         If ComboBox1.SelectedItem = ("B") And ComboBox2.SelectedItem = ("4") Then
    17.             TextBox4.Text = DateTimePicker1.Value.ToString
    18.  
    19.         End If
    20.         If ComboBox1.SelectedItem = ("B") And ComboBox2.SelectedItem = ("5") Then
    21.             TextBox5.Text = DateTimePicker1.Value.ToString
    22.  
    23.         End If
    24.         If ComboBox1.SelectedItem = ("B") And ComboBox2.SelectedItem = ("6") Then
    25.             TextBox6.Text = DateTimePicker1.Value.ToString
    26.  
    27.         End If
    28.      
    29.     End Sub

    Hope it helps,

    sparrow1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  16. #16
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    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...
    Any idea..
    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...
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  17. #17

    Thread Starter
    Lively Member HOTFIX's Avatar
    Join Date
    Sep 2008
    Posts
    91

    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:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.  
    3.         If ComboBox1.SelectedItem = ("A") And ComboBox2.SelectedItem = ("1") Then
    4.             TextBox1.Text = DateTimePicker1.Value.ToString
    5.  
    6.         End If
    7.         If ComboBox1.SelectedItem = ("A") And ComboBox2.SelectedItem = ("2") Then
    8.             TextBox2.Text = DateTimePicker1.Value.ToString
    9.        
    10.         End If
    11.         If ComboBox1.SelectedItem = ("A") And ComboBox2.SelectedItem = ("3") Then
    12.             TextBox3.Text = DateTimePicker1.Value.ToString
    13.      
    14.         End If
    15.  
    16.         If ComboBox1.SelectedItem = ("B") And ComboBox2.SelectedItem = ("4") Then
    17.             TextBox4.Text = DateTimePicker1.Value.ToString
    18.  
    19.         End If
    20.         If ComboBox1.SelectedItem = ("B") And ComboBox2.SelectedItem = ("5") Then
    21.             TextBox5.Text = DateTimePicker1.Value.ToString
    22.  
    23.         End If
    24.         If ComboBox1.SelectedItem = ("B") And ComboBox2.SelectedItem = ("6") Then
    25.             TextBox6.Text = DateTimePicker1.Value.ToString
    26.  
    27.         End If
    28.      
    29.     End Sub

    Hope it helps,

    sparrow1
    Many Thanks "sparrow1" this way of codes is working great, although there are many lines...
    Regrads...

  18. #18
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    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
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  19. #19

    Thread Starter
    Lively Member HOTFIX's Avatar
    Join Date
    Sep 2008
    Posts
    91

    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 …

    Best Regards…
    Last edited by HOTFIX; Oct 1st, 2008 at 04:47 PM.

  20. #20

    Thread Starter
    Lively Member HOTFIX's Avatar
    Join Date
    Sep 2008
    Posts
    91

    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…

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width