PDA

View Full Version : VB6 Combo Box


mhsueh001
05-05-2006, 10:54 AM
Ok, this is back to VB6, after coding in .Net for a while, had to go back and make a fix in an older application and can't seem to figure out how to do this.

How do you set the default value of a combo box in VB6?

I'm using the
cboBox.Text = "my default value"
cboBox.Value = "my default value"

Which appears on the screen in the text of the combo box, but when I try to get the value from cboBox.SelText property it says cboBox.SelText = ""

cboBox.SelText is readonly.

What am I doing wrong and how can I force cboBox.SelText to the default value?

Again, not my code, this is code I had to go back and maintain. The former programmer used the cboBox.SelText command. And since it's spagetti code I don't want to just change this to the .Text property since he probably referenced it in other places as Form1.cboBox.SelText.

Help?!

RealityRipple
05-05-2006, 11:05 AM
a DropDown List combo box has no seltext at all. A DropDown combo's seltext is what is actually selected, and only shows up if the Combo box is selected. your best bet is to do .text instead of .seltext

mhsueh001
05-05-2006, 11:08 AM
a DropDown List combo box has no seltext at all. A DropDown combo's seltext is what is actually selected, and only shows up if the Combo box is selected. your best bet is to do .text instead of .seltext

Well I know that, my problem is this is legacy code. Are you telling me there is no way to select a value in the combo box and have .SelText be given a value?

Is there a way to trigger the event via code so that the cboBox.SelText will have the value set by cboBox.Text?

I hate working on other peoples code, but the former programmer used the .SelText to extract the information from the combo box.

So I've got places all over the code where he's doing something like
If cboBox.SelText = "The first value" then
...Stuff
End if

However setting up my default value with cboBox.Text = "my Default value" or cboBox.Value = "my Default value" is worthless because when I trace through the if statement cboBox.SelText = ""

sindhuKV
05-05-2006, 11:17 AM
Hi,

U can chk

if Combo1.LIstCount > 0 then
set Combo1.LIstIndex=1 [The Default Value ]

Then chk for the .text or .seltext ...it will be available...

Regards.

sindhuKV
05-05-2006, 11:20 AM
n seltext as RealityRipple says is not required in ur case ...Use .Text Instead

mhsueh001
05-05-2006, 11:23 AM
Hi,

U can chk

if Combo1.LIstCount > 0 then
set Combo1.LIstIndex=1 [The Default Value ]

Then chk for the .text or .seltext ...it will be available...

Regards.


In VB6 there is No ListCount Property for the comboBox, there is not ListIndex Property for the combo box, where are these properties, VB6 keeps telling me that these properties do not exist????!?!?!??!

mhsueh001
05-05-2006, 11:40 AM
n seltext as RealityRipple says is not required in ur case ...Use .Text Instead

As I stated. This is not my code, but legacy code from a former programmer.

He has used .SelText all over the place. This combo box obviously contained some important information.

It's also context sensitive. So if information changed some where on the screen the combo box is refreshed with some changes to the data.

Originally if the context changed, the combo box was cleared and re-populated.

My employer wants me to change this so that if the originally selected item exists in the new context generated list to re-select that item as the default.

So I can set the .Text and .Value properties.

However, since the former programmer used .SelText to extract the information from the combo box I have to get .SelText to also hold the same value that .Text and .Value have.

I'm sorry, very frustrated with this. and there's so many forms that are dependent on this combo box value that going through and having to change all the guys code from .SelText to .Text is not really a viable options.

passel
05-05-2006, 05:13 PM
The .SelText property will only have text in it if the combobox has the focus.
If the focus goes to another control, the .Seltext property is empty.
So, the prior programmer's code must have executed with the combobox having the focus.
So the answer is simple. After you set the .Text, do a combobox.SetFocus .

mhsueh001
05-08-2006, 08:19 AM
The .SelText property will only have text in it if the combobox has the focus.
If the focus goes to another control, the .Seltext property is empty.
So, the prior programmer's code must have executed with the combobox having the focus.
So the answer is simple. After you set the .Text, do a combobox.SetFocus .
Thank you passel, that is exactly what I was looking for! :D