Silly ComboBox Question

  • Thread starter Thread starter Mr. B
  • Start date Start date
M

Mr. B

I've been seeking the solution to this. But can't figure it out (sounds
simple enough).

When you Populat a ComboBox, you can select the initial displayed items on
startup simply by setting the TEXT to a valide item in the Combobox.

What I want to do is to select the initial listed item to an item based upon a
varrying veriable.

For example, the combobox is populated with a list of Users.

I then have a command line argument with a user name in it.

Application starts up and the Combobox shows their name.

What's really happening is that I do something like the above. But I'm
opening up an MS Access DB (via ADO). But instead of the User name, I have
only a User code number (ie: BRU001 for Bruce, DAV001 for David, etc.)

My combobox lists the User Code. I've a Text Box that displays the correct
user name based upon the user code (cause they are on the same data base row
and are in synch).

But I can't figure out how to select the initial view of the Combobox (always
get the first user code displayed).

Any help will be appreciated.

Regards,

Bruce
 
Hi Mr B.

I am always a little scared with answering your questions, because I am not
sure if you use the windowforms Combobox or the webform Listdropbox.

But with windowforms Combobox you can do
\\\
combobox.selectedindex = combobox.findstring("name")
///
Cor
 
personally i would use the combobox.findstringexact(string) if you use the
normal findstring you get the first item matching conditions (could be
dangerous i think)

eric
 
EricJ said:
personally i would use the combobox.findstringexact(string) if you use the
normal findstring you get the first item matching conditions (could be
dangerous i think)

Mucho appreciated. I think I was close... but got too frustrated in the so
many failures (:

Bruce
 
EricJ said:
personally i would use the combobox.findstringexact(string) if you use the
normal findstring you get the first item matching conditions (could be
dangerous i think)

Hmmmm.... I don' think this works.

Maybe I need to re-explain my question...

I've a VB.net Windowforms Combobox that gets populated with User ID
information (such as BEV001, FEU001, MAT002, etc) from a data base query on
application startup.

What I want to do (in form load) is to find the User ID index number so that I
can set the Displayed ID on startup.

Graphical display of requirement:

ComboBox1 filled with the following from a data base on startup:
BEV001 (position 0)
DAN001 (position 1)
FEU001 (position 2)
MAT001 (position 3)
TUS001 (position 4)

My user (FEU001) starts up the application. In the app shortcut, I've a
commandline argument where they have their User ID (FEU001).

The app starts... the data base fills the Combobox... now I want to find
FEU001 in the Combobox and set the 'display' for the Combobox to Position 2
(FEU001 position).

Thoughts?

Regards,

Bruce
 
Cor said:
Did you try it?

Yes (unless I did it wrong). But what I got was the current Index of 0.

My Search is a String:

Dim strUserID As String ' User Name Filter

In Form Load I have (I'm using Test.Text to test the Results):

strUserID = UCase("feu001")

cmbUserName.SelectedIndex = cmbUserName.FindString(strUserID)
Test.Text = cmbUserName.SelectedIndex

Regards,

Bruce
 
Cor said:
Did you try it?

Well I found out that your Code DOES work. What I've got is a situation in
which the ComboBox "SelectedIndexChanged" event changes my result on FormLoad
:(

I've run across this before... IF I disable the SelectedIndexChanged stuff...
no problems. But somehow, in the startup, the SelectedIndexChanged falls back
to Index 0.

Bruce
 
Back
Top