以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  如何及时更新时间  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=45782)

--  作者:ap9709130
--  发布时间:2014/2/10 22:49:00
--  如何及时更新时间

我的输入窗口中有个COMBOBOX控件和DATETIMEPICKER控件,我想根据combobox选的选项,DATETIMEPICKER时时生成新的时间。

我在COMBOBOX控件的 VALUECHANGE 事件中输入以下代码:

 

Dim a As WinForm.ComboBox = e.Form.Controls("ComboBox3")
Dim b As WinForm.DateTimePicker = e.Form.Controls("DateTimePicker1")

If a.Value="现金" Then
b.Value = Date.Today
End If

If a.Value= "月结" Then
Dim y As Integer = Date.Today.Year
Dim m As Integer = Date.Today.Month

Dim dt2 As New Date(y, m, Date.DaysInMonth(y, m)) \'获取本月的最后一天

b.Value = dt2
 
End If

If a.Value= "月结30天" Then
Dim y As Integer = Date.Today.Year
Dim m As Integer = Date.Today.Month

Dim dt3 As New Date(y, m+1, Date.DaysInMonth(y, m+1)) \'获取本月的最后一天

b.Value = dt3
 
End If

 

 

为什么选现金时,可以时时更新,而且选了后面这两个不会马上更新时间,但窗口重新打开时,时间又会显示出来,如果可以实现先后面这两个时间也能马上显示出来呢?


--  作者:有点甜
--  发布时间:2014/2/10 22:55:00
--  
 这样改一下

Dim a As WinForm.ComboBox = e.Form.Controls("ComboBox3")
Dim b As WinForm.DateTimePicker = e.Form.Controls("DateTimePicker1")
If a.text ="现金" Then
    b.Value = Date.Today
End If
If a.text = "月结" Then
    Dim y As Integer = Date.Today.Year
    Dim m As Integer = Date.Today.Month
    Dim dt2 As New Date(y, m, Date.DaysInMonth(y, m)) \'获取本月的最后一天
    b.Value = dt2
    
End If
If a.text = "月结30天" Then
    Dim y As Integer = Date.Today.Year
    Dim m As Integer = Date.Today.Month
    Dim dt3 As New Date(y, m+1, Date.DaysInMonth(y, m+1)) \'获取本月的最后一天
    b.Value = dt3
    
End If

--  作者:ap9709130
--  发布时间:2014/2/10 23:27:00
--  
改了,还是不行。
--  作者:ap9709130
--  发布时间:2014/2/10 23:28:00
--  
只有选“现金”时会马上变,其它的都不行。
--  作者:lsy
--  发布时间:2014/2/11 7:58:00
--  

试用版的例子发上来,测试一下。

VALUECHANGE 的使用,有些情况下,需要变通。


--  作者:ap9709130
--  发布时间:2014/2/11 10:42:00
--  
真奇怪,我自己做个简单的例子时,是没有问题的。但在我的例子上就不行。我再检查一下。
--  作者:ap9709130
--  发布时间:2014/2/11 10:59:00
--  

我找到原因了,原来我这个DATETIMEPICKER控件邦定到表的付款时间,所以不行。如果取消邦定就可以了。

但我想不通,其它的不行,怎么选“现金”就可以呢?


--  作者:狐狸爸爸
--  发布时间:2014/2/11 11:01:00
--  

绑定了,就能直接赋值:

 

http://www.foxtable.com/help/topics/2436.htm