Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Code Samples & Tips
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Code Samples & Tips Share your recent discoveries and ideas with other users.

ComboBox 'empty' row

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-13-2009, 10:40 AM
Junior Member
 
Join Date: Jul 2009
Location: Derbyshire, UK
Posts: 36
Default ComboBox 'empty' row

I wanted to use a series of ComboBoxes, to hold option values for a series of parameters for rows in a database (originally an Excel Sheet, but I have saved it as a CSV, and also copied it to a SQLite db).
I load a selected CSV file into a Table control, and save it back after updates..
In order to indicate null fields, I wanted to have an 'empty' row ("") - since you can't set the Combo index to -1..(without re-loading the list).
I edited the lists in the designer, but it seems that empty strings are not saved, so I added an 'Insert(0,"")' statement in App_Start.
I also had to write a Sub to select the appropriate option (or 0) when reading from a Table Cell. Also, because you can't have multiple columns, I include the value and description in the list - like "1 (Good)","2 (Fair)","3 (Poor)","4 (Bad)" - then strip off the 'help' text when saving the value:
(I realise I could have used arrays/ArrayLists to hold the 'codes' and only display the description, but this way users could select an option using the 'code', if they want).
Code:
cboType.Insert(0,""' add 'null' option
...
sTmp = tblData.Cell(
"CType",Row) ' Get value
Find(sTmp,cboType.Name) ' Pass value and Control name..
...
sTmp = cboType.Item(cboType.SelectedIndex) 
' value + description, e.g. "c (Concrete)"
sTmp=RTrim(sTmp) ' I know these lines could be combined, but it was useful to step through/over during debug..
tblData.Cell("CType",Row)=sTmp
...
Sub Find(sValue, sControl)
'    Dim oCombo As Control ' this doesn't work!
'
    oCombo = Control(sControl) ' I wanted to re-use a reference..
    iIndex = 0 ' default (not found)
        sValue = sValue & " " ' add space to avoid matching sub-strings
    If StrCompare(ControlType(sControl),"ComboBox") <> 0 Then Return
    iLen = StrLength(sValue) 
' number of characters to compare
    For iLoop=0 To Control(sControl,"ComboBox").Count - 1
        sTmp = Control(sControl,
"ComboBox").Item(iLoop)
        sTmp = SubString(sTmp,
0,iLen) ' extract 'value' (+ " ")
        If StrCompare(sTmp, sValue)=0 Then ' ignore case
            iIndex = iLoop
            
Exit
        
End If
    
Next
    Control(sControl,
"ComboBox").SelectedIndex= iIndex
End Sub
...
Sub RTrim(sTmp)
    
' return first word (up to space)
    itmp = StrIndexOf(sTmp," ",0' first space
    If itmp > 0 Then sTmp = SubString(sTmp,0,itmp)
    
Return sTmp ' returns whole string, if 'value only'
End Sub
Reply With Quote
  #2 (permalink)  
Old 07-22-2009, 03:51 PM
derez's Avatar
Basic4ppc Expert
 
Join Date: May 2007
Posts: 978
Awards Showcase
Beta Tester Competition Winner 
Total Awards: 2
Default

I may have misunderstood the problem but :

"I edited the lists in the designer, but it seems that empty strings are not saved"

while in the designer, put "" as the first line in the combobox and you have a null string which gives the index of 0 and the value of "".
When running it shows a blank !

See the attached example.
Attached Files
File Type: sbp testcombo.sbp (715 Bytes, 45 views)
__________________
David Erez
Ramat Hasharon, Israel
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
ComboBox Value RandomCoder Basic4ppc Wishlist 7 11-18-2011 11:08 AM
Empty return from http page junglejet Questions (Windows Mobile) 8 02-15-2009 08:39 AM
ComboBox Raytracer Italian Forum 3 04-15-2008 04:15 PM
Error loading empty csf file Scubaticus Bug Reports 4 07-07-2007 11:41 AM


All times are GMT. The time now is 10:33 PM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0