ComboBox ValueMember = Null??? Can't set ValueMember!

G

Guest

Hello all,

I can't seem to set the value member properly in code... I'm using a
ComboBox in DropDownList mode:



Private Class ApplicationsComboBoxItem
Private _Name As String
Private _Application As ApplicationWorker

Public Sub New(ByVal Name As String, ByVal Application As
ApplicationWorker)
_Name = Name
_Application = Application
End Sub

Public ReadOnly Property Name() As String
Get
Return _Name
End Get
End Property

Public ReadOnly Property Value() As ApplicationWorker
Get
Return _Application
End Get
End Property
End Class

Public Sub New()

' This call is required by the Windows Form Designer.
InitializeComponent()

' Add any initialization after the InitializeComponent() call.

ApplicationsComboBox.DisplayMember = "Name"
ApplicationsComboBox.ValueMember = "Application" 'Doesn't set
properly for some reason???
ApplicationsComboBox.SelectedIndex = 0
End Sub



Any ideas?!?!?!?!?!

Thanks!
 
G

Guest

Here's is my code:

Private Class ApplicationsComboBoxItem
Private _Name As String
Private _Application As ApplicationWorker

Public Sub New(ByVal Name As String, ByVal Application As
ApplicationWorker)
_Name = Name
_Application = Application
End Sub

Public ReadOnly Property Name() As String
Get
Return _Name
End Get
End Property

Public ReadOnly Property Application() As ApplicationWorker
Get
Return _Application
End Get
End Property
End Class

Public Sub New()

' This call is required by the Windows Form Designer.
InitializeComponent()

' Add any initialization after the InitializeComponent() call.

For Each App As ApplicationWorker In Engine.Applications
With ApplicationsListView.Items.Add(App.Name)
.Tag = App
.SubItems.Add(App.State.ToString)
AddHandler App.StateChanged, AddressOf
Application_StateChanged
End With

ApplicationsComboBox.Items.Add(New ApplicationsComboBoxItem
(App.Name, App))
Next

ApplicationsComboBox.DisplayMember = "Name"
ApplicationsComboBox.ValueMember = "Application" 'Doesn't set
properly for some reason???
ApplicationsComboBox.SelectedIndex = 0
End Sub



There was a typo in the last message - any ideas why this doesn't work?
 
C

Chris Dunaway

Here's is my code:

Private Class ApplicationsComboBoxItem
Private _Name As String
Private _Application As ApplicationWorker

Public Sub New(ByVal Name As String, ByVal Application As
ApplicationWorker)
_Name = Name
_Application = Application
End Sub

Public ReadOnly Property Name() As String
Get
Return _Name
End Get
End Property

Public ReadOnly Property Application() As ApplicationWorker
Get
Return _Application
End Get
End Property
End Class

Public Sub New()

' This call is required by the Windows Form Designer.
InitializeComponent()

' Add any initialization after the InitializeComponent() call.

For Each App As ApplicationWorker In Engine.Applications
With ApplicationsListView.Items.Add(App.Name)
.Tag = App
.SubItems.Add(App.State.ToString)
AddHandler App.StateChanged, AddressOf
Application_StateChanged
End With

ApplicationsComboBox.Items.Add(New ApplicationsComboBoxItem
(App.Name, App))
Next

ApplicationsComboBox.DisplayMember = "Name"
ApplicationsComboBox.ValueMember = "Application" 'Doesn't set
properly for some reason???
ApplicationsComboBox.SelectedIndex = 0
End Sub

There was a typo in the last message - any ideas why this doesn't work?

Shouldn't that be ApplicationsComboBox.ValueMember = "Value" ? There
is no property named "Application" in your ApplicationComboBoxItem
class.

Chris
 
G

Guest

Spam Catcher,

As far as I know, DisplayMember and ValueMember only work when the
combobox/listbox is assigned a DataSource.

In your case, you might want to add a ToString method to your
ApplicationsComboBoxItem class that returns the Name property. This will be
displayed in the combobox.

Then, when an item in the combobox is selected, the SelectedItem property
will return a ApplicationsComboBoxItem item. You can then get itsApplication
property.

Kerry Moorman
 
G

Guest

Shouldn't that be ApplicationsComboBox.ValueMember = "Value" ? There
is no property named "Application" in your ApplicationComboBoxItem
class.

It was a typo the original post - I posted the correct code - and it still
didn't work!
 
G

Guest

As far as I know, DisplayMember and ValueMember only work when the
combobox/listbox is assigned a DataSource.

What's string is that the NAME field works OK, but the value field does
not. It's so inconsistent...
 

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