Home All Groups Group Topic Archive Search About

Stuck with calss in listbox

Author
16 Apr 2005 7:32 PM
Poohface
ok, lets say I have a class called Veggie and it has a public property
call Apples, Apples is an Int16.

I have a listbox that is filled with Veggies via this line

listbox.Items.Add(New Veggie)

in the sub new of Veggie lets say we set Apples = 10

how can I change  the apples amount?

I'd like to be able to do something like:
(x = the index of the veggie item I want to work with)

listbox.items(x).apples = 20        'or something along that line

what I'm having to do is this:

Dim TempVeggie as Veggie
TempVeggie = listbox.items(x)
TempVeggie.apples = 20
listbox.items(x) = TempVeggie

Is there no way I can edit the Veggie object by refference rather than
making a copy of the object, editing, then copying it back into the
listbox? Seems like there must be a way to do this but I'm miffed.

Norst

Author
16 Apr 2005 7:53 PM
Poohface
hahaha ok ok, I can almost hear you all laughing. It turns out I can
do what I want, it's just that the IDE isn't doing its auto completes
when I do that. I get so reliant on these things I think I'm wrong
when it does not pop down the options when I hit the .

Norst

On Sat, 16 Apr 2005 15:32:41 -0400, Poohface
<poohface@sh*tyerpantsoff.crap> wrote:

Show quoteHide quote
>ok, lets say I have a class called Veggie and it has a public property
>call Apples, Apples is an Int16.
>
>I have a listbox that is filled with Veggies via this line
>
>listbox.Items.Add(New Veggie)
>
>in the sub new of Veggie lets say we set Apples = 10
>
>how can I change  the apples amount?
>
>I'd like to be able to do something like:
>(x = the index of the veggie item I want to work with)
>
>listbox.items(x).apples = 20        'or something along that line
>
>what I'm having to do is this:
>
>Dim TempVeggie as Veggie
>TempVeggie = listbox.items(x)
>TempVeggie.apples = 20
>listbox.items(x) = TempVeggie
>
>Is there no way I can edit the Veggie object by refference rather than
>making a copy of the object, editing, then copying it back into the
>listbox? Seems like there must be a way to do this but I'm miffed.
>
>Norst
>
Author
16 Apr 2005 11:43 PM
Herfried K. Wagner [MVP]
"Poohface" <poohface@sh*tyerpantsoff.crap> schrieb:
> hahaha ok ok, I can almost hear you all laughing. It turns out I can
> do what I want, it's just that the IDE isn't doing its auto completes
> when I do that. I get so reliant on these things I think I'm wrong
> when it does not pop down the options when I hit the .

You are using late binding here, which means that the existance of the
method is determined at runtime.  Instead, consider adding 'Option Strict
On' to the head of your file and use 'DirectCast' for casting (see my other
reply on how to do that).  This will prevent you from making mistakes when
writing code.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
16 Apr 2005 11:42 PM
Herfried K. Wagner [MVP]
Show quote Hide quote
"Poohface" <poohface@sh*tyerpantsoff.crap> schrieb:
> ok, lets say I have a class called Veggie and it has a public property
> call Apples, Apples is an Int16.
>
> I have a listbox that is filled with Veggies via this line
>
> listbox.Items.Add(New Veggie)
>
> in the sub new of Veggie lets say we set Apples = 10
>
> how can I change  the apples amount?
>
> I'd like to be able to do something like:
> (x = the index of the veggie item I want to work with)
>
> listbox.items(x).apples = 20        'or something along that line

\\\
DirectCast(Me.ListBox1.Items(x), Veggie).Apples = 20
///

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
17 Apr 2005 4:02 AM
Poohface
Thank you!!

While this works for the above example, adding 'option strict on' has
broken some portions that I'm not sure of. For example:
(drAccu is a datareader, the ArmCall is the class I have made and
calllist is a listbox)

\\\
Do While drAccu.Read
            Calllist.Items.Add(New ArmCall(drAccu("CustID")))
Loop
///

the "drAccu("CustID")" portion is the issue, stating that the
conversion from system.object to integer is disallowed due to option
strict on.

also:

\\\
If e.State And DrawItemState.Selected Then
///

same issue this time from system.windows.forms.drawitemstate to
boolean is the issue.

Thanks,
Norst

On Sun, 17 Apr 2005 01:42:13 +0200, "Herfried K. Wagner [MVP]"
<hirf-spam-me-here@gmx.at> wrote:

Show quoteHide quote
>"Poohface" <poohface@sh*tyerpantsoff.crap> schrieb:
>> ok, lets say I have a class called Veggie and it has a public property
>> call Apples, Apples is an Int16.
>>
>> I have a listbox that is filled with Veggies via this line
>>
>> listbox.Items.Add(New Veggie)
>>
>> in the sub new of Veggie lets say we set Apples = 10
>>
>> how can I change  the apples amount?
>>
>> I'd like to be able to do something like:
>> (x = the index of the veggie item I want to work with)
>>
>> listbox.items(x).apples = 20        'or something along that line
>
>\\\
>DirectCast(Me.ListBox1.Items(x), Veggie).Apples = 20
>///
Author
17 Apr 2005 4:25 AM
Poohface
ok I fixed the 2nd one with:

If e.State = e.State And DrawItemState.Selected =
DrawItemState.Selected Then


Norst

On Sun, 17 Apr 2005 00:02:49 -0400, Poohface
<poohface@sh*tyerpantsoff.crap> wrote:

Show quoteHide quote
>Thank you!!
>
>While this works for the above example, adding 'option strict on' has
>broken some portions that I'm not sure of. For example:
>(drAccu is a datareader, the ArmCall is the class I have made and
>calllist is a listbox)
>
>\\\
>Do While drAccu.Read
>            Calllist.Items.Add(New ArmCall(drAccu("CustID")))
>Loop
>///
>
>the "drAccu("CustID")" portion is the issue, stating that the
>conversion from system.object to integer is disallowed due to option
>strict on.
>
>also:
>
>\\\
>If e.State And DrawItemState.Selected Then
>///
>
>same issue this time from system.windows.forms.drawitemstate to
>boolean is the issue.
>
>Thanks,
>Norst
>
>On Sun, 17 Apr 2005 01:42:13 +0200, "Herfried K. Wagner [MVP]"
><hirf-spam-me-here@gmx.at> wrote:
>
>>"Poohface" <poohface@sh*tyerpantsoff.crap> schrieb:
>>> ok, lets say I have a class called Veggie and it has a public property
>>> call Apples, Apples is an Int16.
>>>
>>> I have a listbox that is filled with Veggies via this line
>>>
>>> listbox.Items.Add(New Veggie)
>>>
>>> in the sub new of Veggie lets say we set Apples = 10
>>>
>>> how can I change  the apples amount?
>>>
>>> I'd like to be able to do something like:
>>> (x = the index of the veggie item I want to work with)
>>>
>>> listbox.items(x).apples = 20        'or something along that line
>>
>>\\\
>>DirectCast(Me.ListBox1.Items(x), Veggie).Apples = 20
>>///
>
Author
17 Apr 2005 11:16 AM
Herfried K. Wagner [MVP]
"Poohface" <poohface@sh*tyerpantsoff.crap> schrieb:
>            Calllist.Items.Add(New ArmCall(drAccu("CustID")))
> Loop
> ///
>
> the "drAccu("CustID")" portion is the issue, stating that the
> conversion from system.object to integer is disallowed due to option
> strict on.

'New ArmCall(CInt(drAccu("CustID")))'.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>