B4J Question [Solved] Populate ComboBox on File, Load...

Mark Read

Well-Known Member
Licensed User
Longtime User
This is a small project I am working on to create .Desktop files for the RPi. I have the option to load a file already created, modify and save to a new name.

My problem is when I load a file, there are two Mime Type ComboBoxes which should be set. The first one works, the second not.

Can anyone see where I have made a mistake? The files are saved in "Objects-home-pi-Desktop". A sample file is included "MyDesktop.Desktop"

Many thanks.
 

Attachments

  • Desktop.zip
    68.5 KB · Views: 221

rboeck

Well-Known Member
Licensed User
Longtime User
Hi to leoben,

your mistake is only the length of the strings - i made the following change:
B4X:
347       Dim res As String=result(0) & " - " & result(1)
348       If res.Length>60 Then res=res.SubString2(0,60)
349       cbMime2.Items.Add(res)

The strange thing: even if i use cbMime2.Items.Add(result(0) & " - " & result(1)) like your version alreay was, it works. Dont ask me why... (Maybe its a side effect of : 'can cause odd things if no value after ')
Greetings from L.A. ( lower austria)
 
Last edited:
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
your mistake is only the length of the strings - i made the following change:

Tried your changes and still no luck. Still using my original post. It would seem that after loading and setting all the fields, the data changed event is called for each view. For cbMime1, this is required, as it then populates cbMime2 with the correct data. But then in cbMime2, the correct value is shown but is then erased. I do not understand why, Stepping through in debug mode shows everything to be correct.

At a loss!
 
Upvote 0

rboeck

Well-Known Member
Licensed User
Longtime User
I tried it now in release mode, but now i don't see the problem. With the original code from you, the text information for cmMime2 was placed on the whole width of the app and not inside the combobox.
With my correction i select one mime type in cbMime1 and cbMime2 seems to get filled without problems. What exactly is wrong here?
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
With my correction i select one mime type in cbMime1 and cbMime2 seems to get filled without problems. What exactly is wrong here?

The problem is not when you create a new file. If you load an existing file (included MyDesktop.Desktop), the cbMime1 loads correctly but cbMime2 not and I cannot see why.
 
Upvote 0

rboeck

Well-Known Member
Licensed User
Longtime User
My pi is currently not connected, i copied the two files from home to an usb stick, used b4j only on pc an it seems ok. Mime Type ist application, cbMime2 if filled with more then fifty items.
 
Upvote 0

rwblinn

Well-Known Member
Licensed User
Longtime User
Hi Mark,

pls check if attached is working. Have made some changes, like defining subs to handle comboboxes population, stringutils library to load csv, matcher to compare.
 

Attachments

  • Desktop Generator.zip
    68 KB · Views: 204
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
@rwblinn, sorry I am using b4j 3.71 and I cannot run your version. Any way I will try and explain exactly what the problem is.

I have made slight changes in the app as the Mime was incorrect.

  • Take the attached zip file as the new app version.
  • Copy the MyDesktop.txt to a known directory and rename to MyDesktop.Desktop
  • Set a breakpoint on line 358
  • Run in debug mode
  • Click "Load File" and select the MyDesktop.Desktop file you have saved somewhere.
The app will now stop at line 358 "cbMime2_SelectedIndexChanged", Index=1 and Value=3gpp and in the UI the value 3gpp is visible - great.

  • Step through the subroutine
  • After "End Sub" the value in the UI is gone! This is what I don't understand, I have not done anything.
  • Even worse, the sub then runs a second time??????
This has got to be something simple but it is driving me nuts.

My pi is currently not connected

Sorry, my original plan was to use this app on my RPi but the filechooser does not work, therefore it only works in windows.
 

Attachments

  • Desktop.zip
    31.2 KB · Views: 212
  • MyDesktop.txt
    225 bytes · Views: 194
Upvote 0

rboeck

Well-Known Member
Licensed User
Longtime User
Hi, i also tried to find the problem: i think, you are calling cbMime1_SelectedIndexChange.. in line 161 and the system itself does it also. So you get the cbMime2 filling two times and all the side effects. I have tried to remark line 161 and the second filling is gone; but i am not able to look further, if all other functions are working.
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
i think, you are calling cbMime1_SelectedIndexChange.. in line 161

You are correct. The cbMime1 is filled upon starting the app. CbMime2 is filled according to the section made in cbMime1, that means at start, there are no values present.
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
Found a solution but still don't know why it works.

changed:

B4X:
Sub cbMime2_SelectedIndexChanged(Index As Int, Value As Object)
    If Index=-1 Then Return
    Mime2=Value
    DataHasChanged=True
End Sub

to:

B4X:
Sub cbMime2_SelectedIndexChanged(Index As Int, Value As Object)
    If Index=-1 Then Return
    cbMime2.SelectedIndex = Index
    Mime2=Value
    DataHasChanged=True
End Sub

Many thanks to all for the help.
 
Upvote 0
Top