Hi! I'm feeling the burn of .NET; Still getting used to it :)

I'm trying to populate a combo box with instances of a class:
Public Class Shortcut
Private Name As String
Private RealLocation As String

Public Sub New()
Me.Name = "unknown"
Me.RealLocation = "unknown"
End Sub

Public Sub New(ByVal Name As String, ByVal Path As String)
Me.Name = Name
Me.RealLocation = Path
End Sub

Public Function getName() As String
Return (Me.Name)
End Function
Public Function getRealLocation() As String
Return (Me.RealLocation)
End Function

Public Overrides Function toString() As String
Return (Me.Name)
End Function
End Class

My problem is the following code:

With cmb
.ValueMember = "getRealLocation"
.DisplayMember = "toString"

.Items.Add(New Shortcut("Label1", "Full Path1"))
.Items.Add(New Shortcut("Label2", "Full Path 2"))
.Items.Add(New Shortcut("Label3", "Full Path 3"))
End With

When the combo list isn't activated, the combo box shows the results of the
toString function, for the specific instance that is selected. However, when
I click the drop-down button, it shows a list of blank entries. Selecting a
blank entry again shows the results of the toString function of the instance
I apparently selected.

How can I make each entry have a value whent he combobox drop-down list is
showing, not just once a specific item in the list is selected. It's hard to
make choices when there's only blank options =/.

Thanks again!

Re: Populating a Combo Box with instances of a class - problem by Robby

Robby
Wed Dec 01 18:35:16 CST 2004


The ValueMember and DisplayMember only work when the DataSource property is
set. The ComboBox does not have its DataSource property set so it has
nothing to call getRealLocation or toString on. When you select a blank
space it defaults to the ToString method to display it as the selected item.

Robby

"Martin Smith" <smithmb@ufl.edu> wrote in message
news:NVsrd.48894$fY.402@bignews3.bellsouth.net...
> Hi! I'm feeling the burn of .NET; Still getting used to it :)
>
> I'm trying to populate a combo box with instances of a class:
> Public Class Shortcut
> Private Name As String
> Private RealLocation As String
>
> Public Sub New()
> Me.Name = "unknown"
> Me.RealLocation = "unknown"
> End Sub
>
> Public Sub New(ByVal Name As String, ByVal Path As String)
> Me.Name = Name
> Me.RealLocation = Path
> End Sub
>
> Public Function getName() As String
> Return (Me.Name)
> End Function
> Public Function getRealLocation() As String
> Return (Me.RealLocation)
> End Function
>
> Public Overrides Function toString() As String
> Return (Me.Name)
> End Function
> End Class
>
> My problem is the following code:
>
> With cmb
> .ValueMember = "getRealLocation"
> .DisplayMember = "toString"
>
> .Items.Add(New Shortcut("Label1", "Full Path1"))
> .Items.Add(New Shortcut("Label2", "Full Path 2"))
> .Items.Add(New Shortcut("Label3", "Full Path 3"))
> End With
>
> When the combo list isn't activated, the combo box shows the results of
> the toString function, for the specific instance that is selected.
> However, when I click the drop-down button, it shows a list of blank
> entries. Selecting a blank entry again shows the results of the toString
> function of the instance I apparently selected.
>
> How can I make each entry have a value whent he combobox drop-down list is
> showing, not just once a specific item in the list is selected. It's hard
> to make choices when there's only blank options =/.
>
> Thanks again!
>



Re: Populating a Combo Box with instances of a class - problem by Martin

Martin
Wed Dec 01 21:10:18 CST 2004

Hi =)

I was under the impression that the DataSource property was to specify a
data set such as a collection or data table or or arraylist or whatnot...
not a specific piece of data from each object in the combo box. I thought if
you just added a bunch of strings to a combo box, when you pulled down the
combo box to display multiple entries, it would show all the strings... not
blank entries that correspond to the strings.

If I'm adding instances of a certain class to a combo box, what should the
datasource be set as in order to display a specific data member of that
instance, such as the data member "Name" of type string?

I'm still not catching the hang of this :)

Thanks again.

"Robby" <edmund@not.my.email.com> wrote in message
news:e2YbKbA2EHA.1192@tk2msftngp13.phx.gbl...
>
> The ValueMember and DisplayMember only work when the DataSource property
> is set. The ComboBox does not have its DataSource property set so it has
> nothing to call getRealLocation or toString on. When you select a blank
> space it defaults to the ToString method to display it as the selected
> item.
>
> Robby
>
> "Martin Smith" <smithmb@ufl.edu> wrote in message
> news:NVsrd.48894$fY.402@bignews3.bellsouth.net...
>> Hi! I'm feeling the burn of .NET; Still getting used to it :)
>>
>> I'm trying to populate a combo box with instances of a class:
>> Public Class Shortcut
>> Private Name As String
>> Private RealLocation As String
>>
>> Public Sub New()
>> Me.Name = "unknown"
>> Me.RealLocation = "unknown"
>> End Sub
>>
>> Public Sub New(ByVal Name As String, ByVal Path As String)
>> Me.Name = Name
>> Me.RealLocation = Path
>> End Sub
>>
>> Public Function getName() As String
>> Return (Me.Name)
>> End Function
>> Public Function getRealLocation() As String
>> Return (Me.RealLocation)
>> End Function
>>
>> Public Overrides Function toString() As String
>> Return (Me.Name)
>> End Function
>> End Class
>>
>> My problem is the following code:
>>
>> With cmb
>> .ValueMember = "getRealLocation"
>> .DisplayMember = "toString"
>>
>> .Items.Add(New Shortcut("Label1", "Full Path1"))
>> .Items.Add(New Shortcut("Label2", "Full Path 2"))
>> .Items.Add(New Shortcut("Label3", "Full Path 3"))
>> End With
>>
>> When the combo list isn't activated, the combo box shows the results of
>> the toString function, for the specific instance that is selected.
>> However, when I click the drop-down button, it shows a list of blank
>> entries. Selecting a blank entry again shows the results of the toString
>> function of the instance I apparently selected.
>>
>> How can I make each entry have a value whent he combobox drop-down list
>> is showing, not just once a specific item in the list is selected. It's
>> hard to make choices when there's only blank options =/.
>>
>> Thanks again!
>>
>
>



Re: Populating a Combo Box with instances of a class - problem by Robby

Robby
Wed Dec 01 21:32:01 CST 2004


The String type is a basic .Net datatype and the ComboBox knows how to
handel these types. Your Shortcut class is not a basic .Net datatype so the
ComboBox does not know what to do with it except for calling its ToString
method when it is the selected item. Your code tells the ComboBox what
ValueMember and DisplayMember to use but you don't give it a data source to
use them on. Put your objects in a data source assign that to the
DataSource property. All will work well once that is done.

Robby

"Martin Smith" <smithmb@ufl.edu> wrote in message
news:uIvrd.50127$fY.2633@bignews3.bellsouth.net...
> Hi =)
>
> I was under the impression that the DataSource property was to specify a
> data set such as a collection or data table or or arraylist or whatnot...
> not a specific piece of data from each object in the combo box. I thought
> if you just added a bunch of strings to a combo box, when you pulled down
> the combo box to display multiple entries, it would show all the
> strings... not blank entries that correspond to the strings.
>
> If I'm adding instances of a certain class to a combo box, what should the
> datasource be set as in order to display a specific data member of that
> instance, such as the data member "Name" of type string?
>
> I'm still not catching the hang of this :)
>
> Thanks again.
>
> "Robby" <edmund@not.my.email.com> wrote in message
> news:e2YbKbA2EHA.1192@tk2msftngp13.phx.gbl...
>>
>> The ValueMember and DisplayMember only work when the DataSource property
>> is set. The ComboBox does not have its DataSource property set so it has
>> nothing to call getRealLocation or toString on. When you select a blank
>> space it defaults to the ToString method to display it as the selected
>> item.
>>
>> Robby
>>
>> "Martin Smith" <smithmb@ufl.edu> wrote in message
>> news:NVsrd.48894$fY.402@bignews3.bellsouth.net...
>>> Hi! I'm feeling the burn of .NET; Still getting used to it :)
>>>
>>> I'm trying to populate a combo box with instances of a class:
>>> Public Class Shortcut
>>> Private Name As String
>>> Private RealLocation As String
>>>
>>> Public Sub New()
>>> Me.Name = "unknown"
>>> Me.RealLocation = "unknown"
>>> End Sub
>>>
>>> Public Sub New(ByVal Name As String, ByVal Path As String)
>>> Me.Name = Name
>>> Me.RealLocation = Path
>>> End Sub
>>>
>>> Public Function getName() As String
>>> Return (Me.Name)
>>> End Function
>>> Public Function getRealLocation() As String
>>> Return (Me.RealLocation)
>>> End Function
>>>
>>> Public Overrides Function toString() As String
>>> Return (Me.Name)
>>> End Function
>>> End Class
>>>
>>> My problem is the following code:
>>>
>>> With cmb
>>> .ValueMember = "getRealLocation"
>>> .DisplayMember = "toString"
>>>
>>> .Items.Add(New Shortcut("Label1", "Full Path1"))
>>> .Items.Add(New Shortcut("Label2", "Full Path 2"))
>>> .Items.Add(New Shortcut("Label3", "Full Path 3"))
>>> End With
>>>
>>> When the combo list isn't activated, the combo box shows the results of
>>> the toString function, for the specific instance that is selected.
>>> However, when I click the drop-down button, it shows a list of blank
>>> entries. Selecting a blank entry again shows the results of the toString
>>> function of the instance I apparently selected.
>>>
>>> How can I make each entry have a value whent he combobox drop-down list
>>> is showing, not just once a specific item in the list is selected. It's
>>> hard to make choices when there's only blank options =/.
>>>
>>> Thanks again!
>>>
>>
>>
>
>



Re: Populating a Combo Box with instances of a class - problem by Martin

Martin
Wed Dec 01 21:37:19 CST 2004

Thank you very much for all of your assistance.

I'm doing this now:

Dim shortcutList As New ArrayList

shortcutList.Add(New Shortcut("Label1", "Full Path1"))
shortcutList.Add(New Shortcut("Label2", "Full Path 2"))
shortcutList.Add(New Shortcut("Label3", "Full Path 3"))

With cmbGo
.DataSource = shortcutList
.ValueMember = "getRealLocation"
.DisplayMember = "toString"
End With

However, I also tried just adding strings to a combo box... such as
cmb.Items.Add("testing") and it still appears blank until I select it =(

I'm so befuddled =(


"Robby" <edmund@not.my.email.com> wrote in message
news:%23WaP89B2EHA.3840@tk2msftngp13.phx.gbl...
>
> The String type is a basic .Net datatype and the ComboBox knows how to
> handel these types. Your Shortcut class is not a basic .Net datatype so
> the ComboBox does not know what to do with it except for calling its
> ToString method when it is the selected item. Your code tells the
> ComboBox what ValueMember and DisplayMember to use but you don't give it a
> data source to use them on. Put your objects in a data source assign that
> to the DataSource property. All will work well once that is done.
>
> Robby
>
> "Martin Smith" <smithmb@ufl.edu> wrote in message
> news:uIvrd.50127$fY.2633@bignews3.bellsouth.net...
>> Hi =)
>>
>> I was under the impression that the DataSource property was to specify a
>> data set such as a collection or data table or or arraylist or whatnot...
>> not a specific piece of data from each object in the combo box. I thought
>> if you just added a bunch of strings to a combo box, when you pulled down
>> the combo box to display multiple entries, it would show all the
>> strings... not blank entries that correspond to the strings.
>>
>> If I'm adding instances of a certain class to a combo box, what should
>> the datasource be set as in order to display a specific data member of
>> that instance, such as the data member "Name" of type string?
>>
>> I'm still not catching the hang of this :)
>>
>> Thanks again.
>>
>> "Robby" <edmund@not.my.email.com> wrote in message
>> news:e2YbKbA2EHA.1192@tk2msftngp13.phx.gbl...
>>>
>>> The ValueMember and DisplayMember only work when the DataSource property
>>> is set. The ComboBox does not have its DataSource property set so it
>>> has nothing to call getRealLocation or toString on. When you select a
>>> blank space it defaults to the ToString method to display it as the
>>> selected item.
>>>
>>> Robby
>>>
>>> "Martin Smith" <smithmb@ufl.edu> wrote in message
>>> news:NVsrd.48894$fY.402@bignews3.bellsouth.net...
>>>> Hi! I'm feeling the burn of .NET; Still getting used to it :)
>>>>
>>>> I'm trying to populate a combo box with instances of a class:
>>>> Public Class Shortcut
>>>> Private Name As String
>>>> Private RealLocation As String
>>>>
>>>> Public Sub New()
>>>> Me.Name = "unknown"
>>>> Me.RealLocation = "unknown"
>>>> End Sub
>>>>
>>>> Public Sub New(ByVal Name As String, ByVal Path As String)
>>>> Me.Name = Name
>>>> Me.RealLocation = Path
>>>> End Sub
>>>>
>>>> Public Function getName() As String
>>>> Return (Me.Name)
>>>> End Function
>>>> Public Function getRealLocation() As String
>>>> Return (Me.RealLocation)
>>>> End Function
>>>>
>>>> Public Overrides Function toString() As String
>>>> Return (Me.Name)
>>>> End Function
>>>> End Class
>>>>
>>>> My problem is the following code:
>>>>
>>>> With cmb
>>>> .ValueMember = "getRealLocation"
>>>> .DisplayMember = "toString"
>>>>
>>>> .Items.Add(New Shortcut("Label1", "Full Path1"))
>>>> .Items.Add(New Shortcut("Label2", "Full Path 2"))
>>>> .Items.Add(New Shortcut("Label3", "Full Path 3"))
>>>> End With
>>>>
>>>> When the combo list isn't activated, the combo box shows the results of
>>>> the toString function, for the specific instance that is selected.
>>>> However, when I click the drop-down button, it shows a list of blank
>>>> entries. Selecting a blank entry again shows the results of the
>>>> toString function of the instance I apparently selected.
>>>>
>>>> How can I make each entry have a value whent he combobox drop-down list
>>>> is showing, not just once a specific item in the list is selected. It's
>>>> hard to make choices when there's only blank options =/.
>>>>
>>>> Thanks again!
>>>>
>>>
>>>
>>
>>
>
>



Re: Populating a Combo Box with instances of a class - problem by Claes

Claes
Thu Dec 02 03:16:15 CST 2004

Actually, you don't have to specify a DataSource to use DisplayMember
(for ValueMember you need it though)

/claes


"Robby" <edmund@not.my.email.com> wrote in message
news:e2YbKbA2EHA.1192@tk2msftngp13.phx.gbl...
>
> The ValueMember and DisplayMember only work when the DataSource property
is
> set. The ComboBox does not have its DataSource property set so it has
> nothing to call getRealLocation or toString on. When you select a blank
> space it defaults to the ToString method to display it as the selected
item.
>
> Robby
>



Re: Populating a Combo Box with instances of a class - problem by Claes

Claes
Thu Dec 02 03:17:48 CST 2004

1. DisplayMemebr and ValueMember must be set to properties,
not functions like you're doing

2. You're not useing databinding so why bother with DisplayMember
and ValueMember anyway? Just get rid of them and it should work
just fine

/claes



"Martin Smith" <smithmb@ufl.edu> wrote in message
news:NVsrd.48894$fY.402@bignews3.bellsouth.net...
> Hi! I'm feeling the burn of .NET; Still getting used to it :)
>
> I'm trying to populate a combo box with instances of a class:
> Public Class Shortcut
> Private Name As String
> Private RealLocation As String
>
> Public Sub New()
> Me.Name = "unknown"
> Me.RealLocation = "unknown"
> End Sub
>
> Public Sub New(ByVal Name As String, ByVal Path As String)
> Me.Name = Name
> Me.RealLocation = Path
> End Sub
>
> Public Function getName() As String
> Return (Me.Name)
> End Function
> Public Function getRealLocation() As String
> Return (Me.RealLocation)
> End Function
>
> Public Overrides Function toString() As String
> Return (Me.Name)
> End Function
> End Class
>
> My problem is the following code:
>
> With cmb
> .ValueMember = "getRealLocation"
> .DisplayMember = "toString"
>
> .Items.Add(New Shortcut("Label1", "Full Path1"))
> .Items.Add(New Shortcut("Label2", "Full Path 2"))
> .Items.Add(New Shortcut("Label3", "Full Path 3"))
> End With
>
> When the combo list isn't activated, the combo box shows the results of
the
> toString function, for the specific instance that is selected. However,
when
> I click the drop-down button, it shows a list of blank entries. Selecting
a
> blank entry again shows the results of the toString function of the
instance
> I apparently selected.
>
> How can I make each entry have a value whent he combobox drop-down list is
> showing, not just once a specific item in the list is selected. It's hard
to
> make choices when there's only blank options =/.
>
> Thanks again!
>
>



Re: Populating a Combo Box with instances of a class - problem by Martin

Martin
Thu Dec 02 10:34:05 CST 2004

Hi there ---


My classes uses properties now, not functions, and the ValueMember and
DisplayMember are properly assigned to those properties (I think).

I guess my real problem here is even if I add a plain String to a combo box,
it doesn't show up when I open the drop-down list, only once the item is
selected. If I just start a new project, and cmb.Items.Add("item1"), and so
forth, they aren't listed in the box when I drop it down. That is the
problem.

I'm tempted to go rewrite this in Java or worse... eeek!

Thanks.


"Claes Bergefall" <claes.bergefall@online.nospam> wrote in message
news:O9gUY%23E2EHA.3368@TK2MSFTNGP10.phx.gbl...
> 1. DisplayMemebr and ValueMember must be set to properties,
> not functions like you're doing
>
> 2. You're not useing databinding so why bother with DisplayMember
> and ValueMember anyway? Just get rid of them and it should work
> just fine
>
> /claes
>
>
>
> "Martin Smith" <smithmb@ufl.edu> wrote in message
> news:NVsrd.48894$fY.402@bignews3.bellsouth.net...
>> Hi! I'm feeling the burn of .NET; Still getting used to it :)
>>
>> I'm trying to populate a combo box with instances of a class:
>> Public Class Shortcut
>> Private Name As String
>> Private RealLocation As String
>>
>> Public Sub New()
>> Me.Name = "unknown"
>> Me.RealLocation = "unknown"
>> End Sub
>>
>> Public Sub New(ByVal Name As String, ByVal Path As String)
>> Me.Name = Name
>> Me.RealLocation = Path
>> End Sub
>>
>> Public Function getName() As String
>> Return (Me.Name)
>> End Function
>> Public Function getRealLocation() As String
>> Return (Me.RealLocation)
>> End Function
>>
>> Public Overrides Function toString() As String
>> Return (Me.Name)
>> End Function
>> End Class
>>
>> My problem is the following code:
>>
>> With cmb
>> .ValueMember = "getRealLocation"
>> .DisplayMember = "toString"
>>
>> .Items.Add(New Shortcut("Label1", "Full Path1"))
>> .Items.Add(New Shortcut("Label2", "Full Path 2"))
>> .Items.Add(New Shortcut("Label3", "Full Path 3"))
>> End With
>>
>> When the combo list isn't activated, the combo box shows the results of
> the
>> toString function, for the specific instance that is selected. However,
> when
>> I click the drop-down button, it shows a list of blank entries. Selecting
> a
>> blank entry again shows the results of the toString function of the
> instance
>> I apparently selected.
>>
>> How can I make each entry have a value whent he combobox drop-down list
>> is
>> showing, not just once a specific item in the list is selected. It's hard
> to
>> make choices when there's only blank options =/.
>>
>> Thanks again!
>>
>>
>
>