VB.NET: Using String to compare with the Combo Box

  • Thread starter http://www.visual-basic-data-mining.net/forum
  • Start date
H

http://www.visual-basic-data-mining.net/forum

Hi...

Say i have this string call "data" in Form1, this string contains number "5"
value....

how do i pass this string to the Form2 and compare with the combo box
items...

The combo box DropDownStyle is set to DropDownList...
which means when i pass, the SelectedIndex must be subtract or add by 1 to
get the correct items to display...

The Listbox items contain:
One, Two, Three, Four and Five...

How to i actually pass this string to Form2 and Form2 will compare the
number 5 with the items and display Five instead in the combo box
correctly..

Thanks

toytoy -- forum member
http://www.visual-basic-data-mining.net/forum
 
H

http://www.visual-basic-data-mining.net/forum

ooh....."It is the combo box items contain" not "Listbox items contain" in
the previous thread..

To give a clearer picture:

Form2 will be open only after i click on another button in Form1..

data "5" is already in the string and is waiting to be passed to Form2....

The "5" will be comapre accordingly with the items in one of the combobox in
Form2.....

then the combox box in Form2 will display accordingly to the compare
items...In this case which is the "Five" in the items instead of "5"..

That means the combo box will be able to check the items with the string and
display accordingly...

Thanks
 
G

Guest

Form2 can have a reference to Form1. In Form2 declarations:

Private ReferenceForm1 as Form1

If the data variable in Form1 is declared as Public or Friend, you can get
its value from Form2:

ReferenceForm1.data

If data=5, and the ComboBox or ListBox has the SelectedIndex of 5 for
"Five", or the SelectedValue of "5" for "Five", then when you set that
property, "Five" will be displayed.

In the Form2 Load event:

ComboBox1.SelectedIndex = ReferenceForm1.data

or

ComboBox1.SelectedValue = ReferenceForm1.data

In the first case, data would be numeric, in the second, a string. The
SelectedValue property is determined by the ValueMember property of the
ComboBox. It points to a Fieldname. The DisplayMember property also points
to a FieldName, and defines which column is shown in the ComboBox.

www.charlesfarriersoftware.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top