Combobox Search - Forum

Forum Navigation
You need to log in to create posts and topics.

Combobox Search

I asked a while back how to select an entry in a combobox programmatically to have it set on that item.   And at the time the suggestion I had worked.

I've been pulling the hair out of my head trying to get this one to work in a large app I'm setting up, but then created a test on it's down and it still won't work.

 

Create a combobox and enter the following as items

00001-MLMoon
00002-ZedLSmith
00003-TammySBoycott
00004-IdaPDaily

Then in a button place

ListBoxFindItem "NameOfCBox" "00002-ZedLSmith" "[x]"

Does this work for YOU?

Thanks guys

@rcohen

Does this work for YOU?

Yes it does ... variable [x] contains 2

If you need to have this item/text displayed in the ComboBox, all you need to do is ...

SetVar "[NameOfCBox]" "00002-ZedLSmith"

Is this what you want to do ? ... if not, upload your 'test' project (with just one ComboBox and one Button.

proforma.guyot and rcohen have reacted to this post.
proforma.guyotrcohen

Gaev,

Thank you a bunch.   I'm a bit rusty and I was using the Find command and expecting it to do the selection ;-0

I'll wake up soon ;-)

Thanks again sir.

rcohen

@rcohen

If I might suggest...
When you use:

ListBoxFindItem "NameOfCBox" "00002-ZedLSmith" "[x]"

[x] returns the line number of the item in your list.
Now using [x] in this action:

ListBoxGetItem "NameOfCBox" "[x]" "[NameOfCBox]"

should return "00002-ZedLSmith" selected in your ComboBox.

proforma.guyot has reacted to this post.
proforma.guyot

Assuming you have an InputBox or some way the user can select the name in a variable [Name]
You can try:

ListBoxFindItem "NameOfCBox" "[Name]" "[x]"
If "[x]" "=" "0"
AlertBox "Name not Found" "[Name] was not found."
Else
ListBoxGetItem "NameOfCBox" "[x]" "[NameOfCBox]"
EndIf

Vadim, proforma.guyot and rcohen have reacted to this post.
Vadimproforma.guyotrcohen

Thanks @pauljonestindall,

I did get that to work indeed, but what I had forgotten is that this in of itself does not "select" the desired entry (programmatically).   I had forgotten that I had to actually SetVar the variable to the desired entry to make that happen.   See, I haven't used NB in almost five years....  so I forgot a lot of things... which I'm now coming  back to speed with.

Thanks again for the snippet.