Combo box question

  • Thread starter Thread starter Rich
  • Start date Start date
R

Rich

Hi,

I want to create a combo box that shows one value such as NEWCASTLE, but
when you select the item the combo selected item would be another value such
as NEW. I know that you could do this very easily in MS Access but can't
find anyway in VB. Does anyone know how?

Many thanks
Richard
 
Just add another Member to the combobox and use SelectedItem(<your own
member>) to get the value..

Here... use this class!

Private Class ComboItem

Public m_sCaption As String

Public m_oValue As Object

Public Sub New(ByVal Caption As String, ByVal Value As Object)

m_sCaption = Caption

m_oValue = Value

End Sub

Public Overrides Function ToString() As String

Return m_sCaption

End Function

End Class



/Lars
 
in addition

keep in mind you can't use the combobox.selectedvalue this way (it is a very
small price to pay)

get value back
dim ci as ComboItem
ci = ctype(combo.selecteditem,ComboItem)
value = ci.value (in my listitemclass they are properties)
or
value = ctype(combo.selecteditem,ComboItem).value

hope it helps

eric
 
Hi Herfried,

I've tried your exanple, but now my combo box shows Newcastle (New). What I
would like is for it just to show Newcastle, but when you do a
selectedvaluechanged procedure on the combo its value to be New.

Have you any ideas how I can do this?

Many thanks
Richard
 
Hi Herfried,

I have tried your example in my app, but it shows Newcastle (NEW) in my
combo box. What I want if for the combo box just to show Newcastle and when
you do a SelectedValueChanged on the combo box, the combo value to be New.
Do you know how I can do this?

Many thanks
Richard
 
Hi Rich,

Do you mean you want something as this?

Cor

\\\
Private Sub Form1_Load(ByVal sender As _
Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.ComboBox1.Items.Clear()
Me.ComboBox1.Items.Add("Arsenal")
Me.ComboBox1.Items.Add("NewCastle")
Me.ComboBox1.Items.Add("Manchester")
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal _
sender As Object, ByVal e As System.EventArgs) Handles _
ComboBox1.SelectedIndexChanged
If Me.ComboBox1.SelectedItem.ToString = "NewCastle" Then
Dim i As Integer = Me.ComboBox1.FindStringExact("NewCastle")
Me.ComboBox1.Items.RemoveAt(i)
Me.ComboBox1.Items.Insert(i, "New")
Me.ComboBox1.SelectedIndex = i
End If
End Sub
///
 
* "Rich said:
I have tried your example in my app, but it shows Newcastle (NEW) in my
combo box. What I want if for the combo box just to show Newcastle and when
you do a SelectedValueChanged on the combo box, the combo value to be New.
Do you know how I can do this?

I am not sure if I understood your question correctly. Do you want the
item to read "Newcastle (NEW)" if its not selected and shown in the
combobox's dropdown list and do you want the combobox's text to be "New"
when its the selected item?
 
Hi Herfried,

If my sample did not fit for it, I did put every ingredient in it I thought
to do what Rich wants, even when what it is now not what he wants.

Cor
 
* "Cor Ligthert said:
If my sample did not fit for it, I did put every ingredient in it I thought
to do what Rich wants, even when what it is now not what he wants.

I saw your sample, but your sample /deletes/ the "Newcastle (NEW)" item
and creates a new item. If the user selects another item, I would
expect the "Newcastle (NEW)" item to be added again and the "New" item
to be removed.
 
Back
Top