INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

I have a ListBox that was populated

I have a ListBox that was populated

(OP)
I have a ListBox that was populated with field "Name" from a table (Cities) that has two fields(id, name) order by name.
After appending into table, I want to highlight the listbox's item corresponding the record that was just append.
Can you help me, please?

RE: I have a ListBox that was populated

Since there are many ways to poopulate a listbox, can you post your code so far?

For the start you could try calling the .Requery() method of the listbox.

Bye, Olaf.

RE: I have a ListBox that was populated

One way to do this would be to search the Listbox's List array.

First, as Olaf says, you will need to call the Requery method in order to show the new record.

Next, to highlight the newly appended record, suppose lnID contains the ID of the new record, and assume that the ID is in the first column of the listbox. You could do something like this:

CODE -->

WITH Thisform.MyListBox
  FOR lnI = 1 TO .ListCount
    IF .List(LnI, 1) = lnID
      EXIT
    ENDIF
  ENDFOR
.ListIndex = lnI
ENDWITH 

That's just off the top of my head, and not tested by me, but it should give you the general idea.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: I have a ListBox that was populated

That will depend on the type of Rowsource. If you choose Fields and have BoundTo .F. the controlsource is defining the active item and that would automatically be the current row of the table.
Mikes code will work, if you don't do so and populate the Listbox using .AddItem() and the List array of the listbox.

That's why I asked for your code so far, because what you need depends on how you use the listbox.

Bye, Olaf.

RE: I have a ListBox that was populated

Binding to the table and not using the List array directly you do it this way:

BoundColumn: 2
BoundTo:.T. (Well, depends on the data type of the id, look into thread184-1747180: ComboBox help needed..., what's true for a combobox also is true for the listbox)
ColumnCount: 2
Colunwidths: 100,0 (or whatever listbox width is, The 0 width for second column hides the ID value)
ControlSource: sometable.cityid && the cityid picked from the cities table should be stored somewhere else. This might also be a property of an object like thisform.pickedcityid.
RowSource: cities.name, id
RowSourceType: 6

That way the current record in the cities table is determining the listindex and selected item in the listbox and vice versa picking an item moves the record pointer in cities to the picked ID.

To sort this you can't use the listbox sort property but set an index on name as the active tag.

In this scenario, a listbox.Requery() will show a newly appended record and as appending makes it the active record, will also select it in the listbox, unless you move to top or any other record in cities.

An advantage of these settings is the two-way connection of the listbox with the cities workarea. A disadvantage is you can't have multiselect as there only ever is one active row in a workarea.

In the way you describe your population of the listbox, Mikes way to find the item will not work, since you only populate the name and not the id. Mikes approach would need to check whether List(lnI,1) = cities.name, not check for lnID, that would need to populate both the name in the first and the id in the second column, which I do. It is a recommended way to have keys in a listbox, too, to have a means of reidentifying a record. That's the case for both RowsourceTypes 5/6 (Alias/Fields) and also for RowSourceType=0 (None), when populating with Additem. In the latter case appending to your table of course does never change the listbox content, as its data is in its own List, which never is influenced by changing the table data, unless you both append to the dbf and also add the new items via listbox.additem(). The choice of not binding to a workarea has that extra work burden.

Bye, Olaf.

RE: I have a ListBox that was populated

(OP)
Thank you, Olaf
Thank you, Mike

I’m impressed about your quickly and professionally response. You solved my problem and I learned a lot from your target reply.
Actually, I was very unhappy when I saw that after almost ten years from when I leaved VFP for system administration FoxPro stay in about same level of evolution. On the other hand, I was worried about the fact that my VFP’s knowledge are gone on the wind. Now, I am really optimist that soon I’ll be back in business when I see such high-level professionals that spend their time to open eyes of old newbies like me.

By the way, can you point me to some good online resources from where I can update my knowledges? Or maybe new technology that works with VFP? Or even good third-party components? I can’t believe that all VFP’s lovers gone with Microsoft...

Also, I have another question for you: what is the legal status of VFP now? I searched on MS’s website, but I can’t get any information. Is VFP dead and dead owned by Microsoft forever? Is possible to buy a new license? Or, maybe, VFP belongs now to public domain?

Thank you again,
Eugen

RE: I have a ListBox that was populated

Well, you must have been gone for a very long time. Here's a link back to the start of the end: https://msdn.microsoft.com/en-us/library/mt490297

In short, it rather means "VFP is dead and dead owned by Microsoft forever" as you put it.

If you ask me, I am on the way out. I still had to do with FoxPro based software up to January and documenting it now and a foreseeable time. It's replaced with a solution I would question but more important in a way I don't support, that's why I am gone in quite some anger.

Here I just still like to share my knowledge and keep in touch, but I am more and more going other routes. Now not employed anymore and not with many colleagues backing up for me, I look for simpler things and smaller projects. Next up is a small C# business app, the usual simple forms for data entry and I go along with a company trying to evangelize usage of cloud solutions, specifically Google GSuite. You can easily do more than you ever could in Office Automation with VBA in Google Apps Script, which mainly is server side Javascript, though the major benefit is having all Google APIs at hand with great ease of use. This is generating possibilities of cooperation and integration far beyond the regime of the Office suite.

I have one main idea in my own pipeline about Foxpro, to support agile migrations of VFP data, but I tend to evangelize people to move away from Foxpro while sill supporting it. Most devs rather look for the kind of migration wizard automagically turning a Foxpro application into something else, but I don't see that happen, so I concentrate on data migration and support of reimplementing with modern technologies by next generation developers. Others here do have other stances but are more likely to be able to never need to change to something else.

I picked up web development knowledge mainly about PHP/MySQL, which also already is seen on the declining branch of its lifetime, but still thrives very well especially in conjunction with frameworks like Laravel. Then I was always following what Telerik (now Progress) was doing in the MS world and might pick up on Nativescript for app development in the cross-platform league. I look at Docker and Google kubernetes, as I could join a company in Hamburg concentrating on this topic. Anyway, I will rather stay in backend development domains, databases, microservices, migrations, APIs, such things. In the frontend domain at most up to the type of small frontends, you can do in GSuite with Google Forms and App Maker again in the direction of small apps supporting a business. Everything I can support as a one man shop.

Bye, Olaf.

RE: I have a ListBox that was populated

A bit more solely about VFP:

After the end of VFP MS open sourced some parts of VFP10 written in VFP also working with VFP9 and called that the Sedna Add-On. They published it on codeplex (which now itself has ceased to exist) and the VFP community added to that what was soon called VFPX for obvious reasons. There you have your answer about new development since 2007. Most things are in VFPX and now moved and still moving from codeplex to https://github.com/VFPX

Edit: There was a misunderstanding mostly in the industry and press not knowing VFP that Sedna realse meant MS open sourced VFP, but that's nonsense. Many tools within the VFP IDE already were VFP code itself even in VFP6, you always had the xsource.zip giving you source code of wizards and more.

Technologies, which work "with VFP", well, there is no migration tool or path from MS and no other company really made an effort to do so. There are some to me questionable things I won't even mention and maybe the best effort to keep VFP code alive by porting the runtime is Christof Wollenhaupts Guineu. Maybe I am biased for knowing him personally, but this thing also is stuck and not a main product. He extends it as necessary to support his projects and most things are solved for him, which means only a limited subset of the VFP language is supported. I would recommend to forget about continuing with this language with some compatible successor. Go with the flow, means go with current trends and that is - as unfortunate as it is - mainly JavaScript and all the tools and frameworks done with it. Very fortunately having the great jQuery backbone.

I don't know where you came from before you started VFP, was it databases or was it even the way of enabling to write and execute small scripts including any DOS/SHELL commands via RUN, that brought you to VFP? When you say you went system administration, I think Powershell is for you. Not only because the latest meeting of a regional developer group including Christof Wollenhaupt was with a session about Powershell. It is in very short iving you all.NET Framework and more at the commandline and supersedes both the normal Windows cmd.exe Shell and WMI for acting on most anything OS related even including GUI.

Recent Ransomware attacks make Powershell a target to be turned off, but I also see Ransomware detection, protection and removal supported with Powershell scripts. It is just logical that the most comprehensive language available on any Windows machine is used by Malware. MS and more so Secret Services and Governments should learn from this, that there is no beneficial use of kept secret exploits. MS will make it even safer to execute only signed and encrypted scripts and this way may make Powershell the safest way to execute only trusted applications.

OK, that was leading off topic to Powershell. Last, not least you should consider reading the "What's New in X"-books, which Hentzenwerke published for VFP7, 8 and 9. If you even left before VFP6, then you may really start from scratch and take some learning resources from http://www.garfieldhudson.com/.

I think this overall covers you for now.

Bye, Olaf.

RE: I have a ListBox that was populated

(OP)
Hello, Olaf!

First off all I want to ask you to excuse me for my late answer. I must carry out about my health and thus I stayed away from my computer for a while.

Your answers were so comprehensive that I must spent some time to understand all of its implication. Before VFP I was involved in some projects that required Pascal, Pascal OOP (known as Turbo Vision) and Delphi knowledge’s. I loved all Pascal based development environments. After that I came in databases oriented application world and in such way, I met VFP. I used it from FoxPro 2.5 until VFP 7.0 in conjunction with FoxPro tables or MS SQL databases. All time I was stunned about the power, possibilities and easy in use of Fox. I was so happy when I discovered the way in which VFP can cooperate with Windows thru API and Office Automation. Later, Windows scripts helped me in administration’s work. I liked it very much. For my curiosity, I played with PHP and MySQL.

Unfortunately, all of its belongs to the past and I try to have an eye in the future. As you said, I’ll try to "feel" C# and Google GSuite. But, that’s belongs to future.

Nowadays, I am retired and looking for a way to keep my mind in action and, maybe, to earn some extra money. So, I started a small application for some friends. It will be a desktop application using VFP. Work is in progress but... things that I had at small finger sometime now I must discover again. Well, that’s it. The brain is not working like a HDD.

Thank you very much for your values help and I wish you success in your future plans.

Thank you again,
Eugen

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close