Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VFP 6: Combo list RowSource population

Status
Not open for further replies.

Kimed

Programmer
May 25, 2005
104
LT
Hi,

I have a need for a combo box whose list of possible values is populated dynamically, depending on other controls' values. In the end I chose to do it with RowSourceType=1 and RowSourse as a string (I also tried arrays, but it didn't go well). It looks like this:
Code:
m_list=""
SCAN FOR <<condition>>
  m_list=m_list+field1+","+field2+","          && combo's ColumnCount=2
ENDSCAN
IF LEN(m_list)>0
  m_list=LEFT(m_list,LEN(m_list)-1)            && remove last trailing comma)
ENDIF
thisform.combo1.RowSource=m_list
It all goes well, except that the list contains one extra empty line in the end. I'm out of ideas why it might happen. Fields' contents doesn't have commas inside, the total length of the resulting string is lesser than 256, the string doesn't contain trailing whitespaces, the table browsed by <<condition>> doesn't contain unnecessary records (including possibly deleted ones). What could cause an extra line to appear?

Thanks.
 
Why bother with the string etc etc...Why not load straight into the combobox.
Code:
In combobobox's Dropdown:
with this
.clear
.columncount = 2
.columnwidths = "100,100" &&&& set your size 
 scan for <<condition>>
   .additem(<<field1>>)
   .list(.newindex,2) = <<field2>>
 endscan
endwith
 
What do you mean when you say that the list contains an empty line?

Jim
 
Kimed,

I see you have code that removes the final comma. That code looks OK to me. But if I was you, the first thing I would do would be to check that the final comma has indeed been removed. You can do that simply by displaying m_list at the end of the code.

If nothing else, it would eliminate an obvious possibility.

That said, I agree with Imaginecorp. I'd be inclined to populate the combo either with AddItem, or from an array or cursor.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
[sigh] Problem solved, thanks everyone, sorry for bothering. It was my own absence of mind to switch combo's style to "dropdown *list*" during earlier experiments and I just forgot to turn it back.

Still, thanks Imaginecorp for pointing at AddItem - it allowed me to make lists with longer lines without breaking total 255 characters limit.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top