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

  • Thread starter Thread starter Guest
  • Start date Start date
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!
 
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?
 
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
 
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
 
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!
 
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...
 
Back
Top