以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  设置组合框默认值的代码为何无效啊?  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=114410)

--  作者:guosheng
--  发布时间:2018/2/5 16:42:00
--  设置组合框默认值的代码为何无效啊?
通过窗口的aferload事件设置:
Dim str As WinForm.ComboBox = e.Form.Controls("产值年份")
Dim y As Integer=Date.today.year
Dim y1 As Integer=y-1
Dim y2 As Integer=y+1
str.ComboList=y1 & "|" & y & "|" & y2
str.SelectedIndex =1                                设置组合框的默认选中值   
测试后,组合框的默认值为什么还是空呢

--  作者:有点甜
--  发布时间:2018/2/5 16:51:00
--  

1、组合框那里,下拉的年份正确了没有?

 

2、改成这样呢? str.Text = y


--  作者:guosheng
--  发布时间:2018/2/6 8:45:00
--  组合框默认值仍然无效。 str.Text = y
在窗口的aferload中添加str.Text = y,组合框的默认值仍然为空啊。
下拉列表已经成功生成了。
请老师帮忙看看怎么回事。

Dim str As WinForm.ComboBox = e.Form.Controls("产值年份")
Dim y As Integer=Date.today.year
Dim y1 As Integer=y-1
Dim y2 As Integer=y+1
str.ComboList=y1 & "|" & y & "|" & y2
\'str.SelectedIndex =1
str.text=y
[此贴子已经被作者于2018/2/6 8:45:53编辑过]

--  作者:有点甜
--  发布时间:2018/2/6 8:58:00
--  

你这个控件绑定了表列吧,如果是,就这样写

 

Dim str As WinForm.ComboBox = e.Form.Controls("产值年份")
Dim y As Integer=Date.today.year
Dim y1 As Integer=y-1
Dim y2 As Integer=y+1
str.ComboList=y1 & "|" & y & "|" & y2
str.text=y
str.WriteValue


--  作者:guosheng
--  发布时间:2018/2/6 9:07:00
--  加入代码str.WriteValue后运行错误。该如何解决啊?
详细错误信息:
未将对象引用设置到对象的实例。
Dim str As WinForm.ComboBox = e.Form.Controls("产值年份")
Dim y As Integer=Date.today.year
Dim y1 As Integer=y-1
Dim y2 As Integer=y+1
str.ComboList=y1 & "|" & y & "|" & y2
\'str.SelectedIndex =1
str.text=y
str.WriteValue

--  作者:有点甜
--  发布时间:2018/2/6 9:33:00
--  

 你肯定有其它代码更改了控件的值,下面这段代码没问题

 

Dim str As WinForm.ComboBox = e.Form.Controls("产值年份")
Dim y As Integer=Date.today.year
Dim y1 As Integer=y-1
Dim y2 As Integer=y+1
str.ComboList=y1 & "|" & y & "|" & y2
str.text=y

 

 请把其余全部代码清空,单独留上面的代码(aftarLoad、控件各个事件代码)


--  作者:guosheng
--  发布时间:2018/2/6 9:41:00
--  
最后我在表的datarowadded中,赋初始值,解决了。