如何在DateTimePicker上设置日期 [英] How do i set a date on a DateTimePicker

查看:141
本文介绍了如何在DateTimePicker上设置日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此按钮用于保存

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        student(fila, 0) = TextBox1.Text
        student(fila, 1) = TextBox2.Text
        student(fila, 2) = TextBox3.Text
        student(fila, 3) = ComboBox1.Text
        student(fila, 4) = DateTimePicker1.Text
        If RadioButton1.Checked Then
            student(fila, 5) = 0
        End If
        If RadioButton2.Checked Then
            student(fila, 5) = 1
        End If
        fila = fila + 1
    End Sub



此按钮用于搜索



This button is to search

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        For fila = 0 To 9
            For col = 0 To 5
                If TextBox1.Text = student(fila, col).ToString() Then
                    TextBox2.Text = student(fila, col)
                    TextBox3.Text = student(fila, col)
                    ComboBox1.Text = student(fila, col)
                    DateTimePicker1.Text = student(fila, col)
                    If student(fila, col) = 0 Then
                        RadioButton1.Checked = True
                    End If
                    If student(fila, col) = 1 Then
                        RadioButton2.Checked = True
                    End If
                End If
            Next col
        Next fila
    End Sub



如您所见,我将选择的日期保存在字符串变量中,如何将datetimepicker设置为该变量中保存的日期?
谢谢...



As you can see i save the date picked on a string variable, how do i set the datetimepicker to the date that is saved on that variable??
Thanks...

推荐答案



您可以尝试:

Hi,

you can try:

DateTimePicker1.Value = Convert.ToDateTime(student(fila, col))



这肯定不适用于Button2_Click中的代码-我必须承认我不明白您在这里所做的事情.

看一下这个功能.这可能是最好的方法:

http://msdn.microsoft.com/en-us/library/ch92fbc1.aspx [ ^ ]



This will certainly not work with your code in Button2_Click - I have to admit that I don''t understand what you are doing there.

Have a look at this function. It will probably be the best way:

http://msdn.microsoft.com/en-us/library/ch92fbc1.aspx[^]


我成功了,我做了一个Date变量
I got it working, i made a Date variable
Dim date(10) As Date


我将日期保存在变量中


i saved the date on the variable

date(fila) = DateTimePicker1.Value


然后我将date变量的内容放入datetimepicker


then i put the content of the date variable into the datetimepicker

DateTimePicker1.Value = fecha(fila).Date


这篇关于如何在DateTimePicker上设置日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆