VB6:组合框样式2.文本属性行为 [英] VB6: combo box style 2. Text property behaviour

查看:150
本文介绍了VB6:组合框样式2.文本属性行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的一个VB6项目表单有一个组合框。它的样式设置为2(下拉列表框)。



当样式设置为2时,其Text属性变为只读。我们不能为它赋值。



但在我们的项目中,有人编写了一些代码来为Text属性分配字符串,并且工作正常。



One of our VB6 project form is having a combo box. It's style is set to 2(Drop-down List Box).

When style is set to 2, its Text property becomes read-only. We cannot assign value to it.

But in our project some one has written code to assign string to Text property, and is working fine.

combobox1.Text = "Something" 'working





如果我创建具有相同属性的相同类型的组合框,我无法将字符串分配给文本属性。我收到错误运行时错误383:text属性是只读的





If i create a same kind of combo box with same properties, i am not able to assign string to text property. I am getting error runtime error 383 : text property is read-only

combobox2.Text = "Something" 'Not working





任何人都可以帮我理解我所缺少的东西



我有什么尝试过:



我尝试添加相同的控件,其设置与我的新控件的属性相同。



Can anyone help me understanding what i am missing

What I have tried:

I tried adding same control with same properties set to my new control as that of old one.

推荐答案

将VB6组合框设置为下拉列表框,如果组合框的项目列表中包含该文本,则可以为文本属性赋值一个值。它实际上相当于以编程方式选择现有条目。



如果它不适用于你的combobox2那么你还没有在该组合框中添加Something文本或者代码在列表完全填充之前运行(例如,在Form加载事件中)。



注意完全......如果现有项目文本以Something开头但后跟其他字符(包括空格)则不起作用。它也区分大小写。
With VB6 combo boxes set to 'Drop-down List Box' you can "assign" a value to the Text property if the combobox list of items contains exactly that text. It is actually the equivalent of programmatically selecting an existing entry.

If it is not working for your combobox2 then you have not yet added the text "Something" to that combobox OR the code is running before the list is fully populated (e.g. in a Form load event).

Note the "exactly" ... if an existing item text begins with "Something" but is followed by other characters (including spaces) then it will not work. It is also case sensitive.


这篇关于VB6:组合框样式2.文本属性行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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