PDA

View Full Version : Select Text In Combobox


holtzy
02-18-2003, 01:50 AM
What is the command to set the selected text in a non-editable combobox?mycombobox.setSelectedText("whateverIwantSelected")Something like this?

Rupert
02-18-2003, 03:12 AM
I managed to change the text in the labels array ok but I cant seem to get it to alter the onscreen display:
_level0.mycombobox.labels[0] = "new text";
trace(_level0.mycombobox.labels);

Anybody else?

holtzy
02-18-2003, 04:25 AM
This works, but it's a slow way to get it done. Any other takers?
while(mcForm.cmbYear.getValue() != items[1]){
mcForm.cmbYear.setSelectedIndex(i);
i = i + 1
}

CyanBlue
02-18-2003, 06:34 AM
Um... Call me dumb, brother... But I don't get your question... What do you mean by 'set the selected text in a non-editable combobox'??? What are you trying to do??? :(

holtzy
02-18-2003, 02:25 PM
No problem...let's say I have a combobox with 50 different years in it which are not in order. After I dynamically load the fifty different years in it I want the combobox to automatically select the year "1997", and stay there until the user changes it. I can't get it to do this because I don't know the index number of the year "1997" in the combobox. Make sense?

CyanBlue
02-18-2003, 09:32 PM
Well... If that is the case, you have to run the loop to see if '1975' exists or not as you have in the while loop... It might take some time to see if that data exists or not, but I don't think it will be that bad since you are not supposed to add more than 400 data in the combobox anyways... Doing a loop with 400 elements will take no more than a second, I think... :DdataArray = new Array(1955, 1935, 1958, 1983, 1975, 1936, 1988, 1973, 1989, 1992, 1945, 1958, 1963, 1934, 1977);
_level0.attachMovie("FComboBoxSymbol", "testCB", 100, {_x:25, _y:25});
_level0.testCB.setDataProvider(dataArray);

for (i = 0 ; i < dataArray.length ; i++)
{
if (_level0.testCB.getItemAt(i).label == "1975")
{
_level0.testCB.setSelectedIndex(i);
break;
}
else
{
_level0.testCB.setSelectedIndex(0);
}
}I just added 'break;' to get out of the loop as soon as the data has been found, or the default will set it to the first item in the array...

holtzy
02-18-2003, 10:02 PM
That's similar to what I was trying in a previous post, but I have decided to make the comboboxes editable. I will just have to write a check to make sure that the entry is valid. Thanks! Hope all is well.

CyanBlue
02-18-2003, 10:22 PM
Arg... I can't find this darn thing... I have seen freddycodes' example within a week period, but I can't seemd to find that thread... Anyways... freddycodes posted this... Check it out and see if you want this... If you do, all you have to is to ask freddycodes... :D
http://www.irq11.com/~louie/portfolio/swf/smartCombo.html

holtzy
02-19-2003, 10:55 PM
I don't understand? I went to the link, but there was no selected text in the combobox....

CyanBlue
02-20-2003, 12:12 AM
Oh... There is not preselected text in that combobox... I just showed you the url because I wanted you to see how other features are done in there... There are some nice features in his combobox... :)

holtzy
02-20-2003, 03:09 AM
Oh, my bad. I was looking for the selected text thing. I'll take a look at it again. Thanks yet again!

freddycodes
02-20-2003, 04:39 AM
Well if you knew the initial value you wanted set, you could just add that one first. Consider this


years = [];
years.push({data:1998,label:1998});
for(var i=1990;i<2010;i++) {
if(i != 1998) years.push({data:i,label:i});
}
myBox.setDataProvider(years);

holtzy
02-20-2003, 02:08 PM
I'm not familiar with "push", but if you're saying that when I populate the combobox, just stick the one I want selected in first, that would work. Except I don't find out what they select till after combobox is already filled. I can't believe that the combobox component doesn't have a function that selects certain text in the combobox....guess I'm just used to VB.