_urlcombobox problem

I am trying to use this object since it offers much convenience as opposed to shellexecute. This is the problem I run into. When I issue commands in INIT:

THIS.AddItem ("www.msn.com",1,1)

THIS.AddItem("www.yahoo.com",2,1)

THIS.AddItem("www.pdr.net",3,1)

The items appear in combobox doubled. This set of urls is repeated twice! Not every url is doubled individualy but the whole set of three urls.

This is not all. When I removed the last item, I saw five items in the box: msn.com and yahoo.net were doubled but the last one, pdr.net which is supposed to have been gone appeared as a single item. The control remembers it and cannot be forced to forget.

Also I am wondering what the meaning of columns is in this control. It is the last integer in command that determines the column number. In this case it is 1. When I tried to set the columnCount to 2 and assign a character string to this column I could make the second column appear and the values went there but not opposite to the urls in the first column. They are hanging out there on their own.

Where can I read more about it The stuff in help on _urlcombobox class is very basic.

Thanks.




Answer this question

_urlcombobox problem

  • vmmdesai

    Thank you very much, Tamar. It is very helpful. This distinction is very important.

  • xjchia

    Well. a minute after I declared pessimistically that the problem still remained, I solved it completely. The doubling is eliminated entirely by a simple trick:

    THIS.cUrlHistoryTable = ""

    in INIT.

    That's it. It is the result I've wanted all along. Looks very cute.

    Thanks.



  • ghawkes

    Alex - as I said before, I've never used the _URLComboBox and don't really have a use for it. However, I have spent plenty of time learning about comboboxes generally and they work as documented.

    In particular, AddItem always adds a new row, while AddListItem lets you populate additional columns of an existing row. NewIndex and NewItemID behave as expected.

    I think you're missing the difference between the two ways of addressing a combo's data. Here's an excerpt from my book, Hacker's Guide to VFP 7, that explains the two numbering systems:

    <begin quote>
    The key to understanding the difference between the "item" and the "listitem" or "itemid" methods (not just Add and Remove, but a bunch of others, too) is to understand that Microsoft thought they were doing us a favor (and they were) in providing the two different numbering systems used for elements of a list or combo box.

    The first numbering system is based on the "what you see is what you get" school of thinking. Each item is assigned a number based on its physical position in the list. This is called the item's ListIndex (or, more briefly, Index). As new items are added or old items are removed, an item's ListIndex can change. Changing the Sorted property also can change an item's ListIndex. So can moving items around with the mover bars. Fundamentally, a ListIndex is a fleeting thing.

    The other numbering scheme is more permanent. When an item is added, it's assigned a unique ID number called ItemId. That item keeps that ItemId as long as it's in the list. No other item in the list will ever have that ItemId.
    <end quote>

    Tamar

  • kashiro

    You are right. The table has been found. It is of some help, however the doubling of links is still unavoidable with preloading.

    Thanks.



  • Geof2323

    There is more to it. I suggest you may look into it deeper. It makes sense because it is potentially a useful control but as far as I can tell nobody knows at this time how to use it properly.

    I tried newIndex and newItemId before and they did not work either. This is why I did not bother mentioning them at all.

    Suppose you have an array ARR1 of url links. The size of the array is 16. You do the following in the INIT of the control:

    FOR ii = 1 TO ALEN (Arr1,1)

    THIS.AddItem (arr1[ii],THIS.newIndex,1)

    ENDFOR

    will give you an error after about 3 iterations.

    I also tried to input my own index (the loop cycle counter: ii) in place of the index. The same thing happens: it takes only three values, and then breaks down.

    If you do this:

    ACTIVATE SCREEN

    FOR ii = 1 TO ALEN (arr1,1)

    THIS.AddItem (arr1[ii],1,1)

    THIS.newIndex

    THIS.newItemID

    ENDFOR

    you will get a series of numbers (two per cycle) but they are totally erratic. There are repeats. You can see the same index three cycles in a row, the numbers may reverse, etc.

    After I saw it I stopped wondering why I could not get the second column straight.

    I cannot investigate it any further. It is not worth my effort at this time. It works, sort of, with one column for me. I also have other options but it would be nice if somebody more experienced did a thorough investigation on a practial level, not just theoretically.



  • fs_07801

    It still does not work. The items do appear in the second column but they are misplaced. The whole thing looks screwy. I had to make a number of modifications to get even that. The .newItem you suggested gave me an error right of the bat. There is no such property it said.

    I had to put an integer, the row number in its place but even after that the things improved marginally, as I said.

    Thanks.



  • Dan Jimenez

    NewItem was a typo on Marcia's part. There are two related properties, NewIndex and NewItemID. Use NewItemID in this case.

    Tamar

  • Adolfo Wiernik

    Thank you, Tamar and Marcia. I will have to work on it all. Just one comment. I did a search for urlcombobox on fox wiki and found a quote (a highlight actually) which seems to indicate that people ran into this doubling problem before. I could not find the actual place on the web page since it was so long and I had no time to scan it all.

    I also tried this approach.

    THIS.BoundColumn = 1

    THIS.ColumnCount = 1

    THIS.ColumnWidths = "120,0"

    THIS.RowSourceType = 1

    THIS.RowSource = "www.msn.com,www.yahoo.com,www.pdr.net"

    I got the same result. Here I tried to settle for just one column to siplify things. The lines were doubled and trippled. It looks like you are right, the combobox is bound to a table and it keeps a track of the history. Where is this table located What is its name The method "openurlhistory" did not seem to work at all. It was just ignored.

    Thanks.



  • Jarek Maciag

    As far as I can tell, this control is not meant for you to preload a list of URLs, but for users to type in URLs and then have them remembered, as most browsers do.

    You can figure out where that data is being stored by looking at the code for the class. Looks like a property of the class, cURLHistoryTable, points to the table.

    Tamar

  • alwz_nikhil

    Alex,

    If you instead conditionally added your "base" items to the cbo then your users would retain their history of the places they've needed to go that you didn't think about when you wrote the code. *s*



  • ZhouRendong

    Also I am wondering what the meaning of columns is in this control. It is the last integer in command that determines the column number. In this case it is 1. When I tried to set the columnCount to 2 and assign a character string to this column I could make the second column appear and the values went there but not opposite to the urls in the first column. They are hanging out there on their own.

    In addition to Tamar's advice on using the AddListItem() method, just rememeber that the AddItem() method adds an entire row to the combo's internal list. So, if you have multiple columns, you need to intialize them just as you would the elements of any other array:

    WITH This

      .AddItem( "Apple" )

      .List[ .NewIndex, 2 ] = "Red"

      .AddItem( "Grape" )

      .List[ .NewIndex, 2 ] = "Green"

    ENDWITH

     



  • russk

    NewItem was a typo on Marcia's part.

    Good catch. Thanks. I meant NewIndex, so I have modified the code.



  • TLin

    I've never used this class, but a quick look at the code indicates that it stores a list of previously visited URLs in a table and initially populates the combo with those. That's probably why you're seeing extras.

    As for columns, VFP's comboboxes can show multiple columns. However, the AddItem method always adds a new item, no matter which column you specify. To populate columns after the first, you need to use AddListItem. Here's an example from my book "Hacker's Guide to Visual FoxPro"; it's meant to run from a method of the combo itself:

    SELECT Employee
    SCAN
    This.AddListItem(Last_Name)
    This.AddListItem(First_Name, This.NewItemId, 2)
    This.AddListItem(Title, This.NewItemId, 3)
    ENDSCAN

    Tamar

  • _urlcombobox problem