Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Combobox doesn’t react on text input from textfile

 
Karolien Zomers
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At this point I’ve got a combobox that gets its content from a SQLite database.
The user can select an item from the combobox or type the name of the item and then select it. When an item name is selected, the item is shown on the screen. Those functions work.

I made an open and a save function. The save function saves the name of the item in a text file. The open function opens the name of the item in the combobox. But then nothing happens. It doesn’t matter if I hit Enter. It seems that the combobox doesn’t recognize the text as input.

It is important to save and open the name of the item and not the item itself, because the item can be changed in the database. Then an old item would be shown and not the updated one.

I want the combobox to open the item when the item name is loaded in the combobox. What are the solutions for this problem?

This is the code that loads the name of the item in the combobox:

private function openComplete(e:Event):void
{
try
{
var data:ByteArray = fileRef.data;
combo.textInput.text = data.readUTFBytes(data.bytesAvailable);


}
catch(errObject:Error)
{
Alert.show("Foutmelding: " + errObject);
}
}
 
Alvin Watkins
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Karolien,

Can you please put any code in the "code" tags? If you look at the buttons on your post window, you'll see a button called "Code". Press that button and then put your code there. Also, I don't understand your question. Is it possible that what you're meaning to do is to set the ComboBox selection such as

 
Karolien Zomers
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Alvin,

I'm not sure which other code I have to post. Because the other code works fine.

I want the name that is loaded from the textfile into the combobox to be selected from the list. I tried to use myComboBox.selectedItem, but that doesn't work because nothing is selected. That is the problem. The item isn't selected automatically. Once an item is selected everything works just fine. But I don't want the user to select the item, when the item is loaded into the combobox. The user will expect that the item will be selected automatically. Is that possible?

I hope my problem is better explained this way.

 
Alvin Watkins
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Forgive me if I'm still missing the point, but from the ActionScript 3.0 API on ComboBox().selectedItem:

"The item that is currently selected. Setting this property deselects the currently selected item and selects the newly specified item."

So, if you know what item is supposed to be selected, because you loaded it into your program, then all you need to do is to say:



You must, however, also make sure that the item you are selecting exists within the data model that ComboBox is based on. Otherwise, you are setting the ComboBox to an item that does not exist.

When I have had data models for ComboBox in the past, they have usually been ArrayCollections. I then build a method that allows me to add items to and take items out of the ArrayCollection that ComboBox's data model is based upon. Either way, make sure that the items you're adding actually exist within the data model.
 
Karolien Zomers
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is that nothing is selected yet. So the combobox.selectedItem doesn't work.
The name that is loaded into the textbox of the combobox exists, because it was saved from the very same combobox. The names of the items don't change, so it isn't possible to open a name that doesn't exist in de database (where the combobox gets it names from).
 
Karolien Zomers
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to do the opposite of combobox.selectedItem. Instead of having a selected item and getting the name, I have a name and I want to select the item.
 
Karolien Zomers
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found the problem.
I’ve tried to loop through the array of names before. It got me thinking. It had to work, but it didn’t.



I found out that when I looped throught the data, the method that opened the item wasn't used anymore. In the combobox I used change to call the method.
When I use caretChange instead of change, the method is used.
So when I open the file with the itemname, the itemname is loaded in the combobox and the item is opened on the screen.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic