Ok, here's the deal. I tried to do this and it didn't work:
[Child Form "Form2"]
Event OK (ByVal item as Object)
'I cast it as Object simply because that's the type of a Listbox Item.
Private Sub Button1(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Raiseevent OK(Lisbox1.selecteditem)
End Sub
--------------------------------
[Parent Form "Form1"]
Private Sub Form2_OK(ByVal item as Object) Handles Form2.OK
Listbox.Items.add(item)
End Sub
the fresh new item on Form1's Listbox shows "System.Data.DataRowView"
what's going on?!?!?!?!
thanx for all previous replies!
ignacio
----------------------------------------------------------------------------
------
>Hi Ignacio,
> I think it has something to do with not giving valuemember and
displaymember
> values (what values could I give? it's not bound)
You can bind a ListBox (via DataSource) to *any* object that implements the
IList interface. This includes Array or ArrayList. You just need to fill one
of these with suitable objects with a property for the string to display and
another for the data you need and set the DisplayMember and ValueMember
properties of the ListBox.
Cheers
Doug Forster
"Ignacio Martínez" <msnews@puturra.com> wrote in message
news:e3fiPPX0DHA.1708@TK2MSFTNGP12.phx.gbl...
> thanx for the 2nd response
> I had tried casting the [Object] Object from the child form to the parent
> form, but I only got "System.Listbox....something", instead of the text of
> the item I passed.
> I think it has something to do with not giving valuemember and
displaymember
> values (what values could I give? it's not bound)
>
> it's pretty damn hard!
> I wish I only had to show the text for the item, but I really need the ID
to
> continue using that item for other purposes on the parent form.
> anyway, thanx
> I posted this message on other MS groups but I got no reply so far.
> nice weekend!
>
> <anonymous@discussions.microsoft.com> escribió en el mensaje
> news:014b01c3d16e$4acbe4f0$a601280a@phx.gbl...
>
> >-----Original Message-----
> >ok, so basically I can't manually set the valuemember of
> a listbox item
> >(webcontrols are more flexible in this cases...)
> >
> >thanx!!!!!!!!
> >
> >"TB" <tbrown92030@kaxy.NOSPAM.com> escribió en el mensaje
> >news:01a401c3d168$ed142430$a401280a@phx.gbl...
> >
> >>-----Original Message-----
> >>Hey group!
> >>first of all, happy new year to everyone.
> >>
> >>I have a small problem that I haven't worked out yet and
> >it's driving me a
> >>little crazy.
> >>I have two forms with a listbox control on each one.
> >>
> >>the child form passes the selecteditem to the parent
> form.
> >>but I want to pass the whole item (Value Member, Display
> >Member) and I have
> >>no clue on how to do this.
> >>what I could do was to pass just the text as a parameter
> >in an event on the
> >>child form.
> >>but that doesn't suit my needs.
> >>
> >>I can't use databindings, because I need to do this
> >manually.
> >>is there a way to add the whole item????
> >>
> >>thanx in advance!
> >>ignacio martínez
> >>buenos aires, argentina.
> >>
> >
> >Ignacio,
> >
> >Usually when I need to get more data for a selected item
> >in a listbox I will set each item's "Tag" property to an
> >object that contains what I need -- usually an instance of
> >whatever object I am working with. Given a selected item,
> >you just cast it's Tag value to what you expect and you're
> >off!
> >
> >-- TB
>
> Lo siento, Ignacio,
>
> I'm afraid I didn't read your post carefully enough the
> first time around. ListBox controls are different from
> the ListView controls that I'm more used to. The latter
> accept "smarter" items (where each can have a tag). A
> listbox does not.
>
> Ok, so let me see if I am understanding your problem.
> When the user selects an item in your child form's listbox
> you want to pass along both the display member string
> *and* value member string for that selected object up to
> the parent form.
>
> The value data is, of course, the "SelectedValue" for the
> listbox. There is no corresponding "SelectedDisplay", but
> you can use "SelectedItem" to get the object you
> originally added to the listbox, cast it to the right type
> of thing, and then access the property directly. You can
> also get the value member this way.
>
> But you're right -- the ListItem Web object allows the
> text and value members to be specified but the normal
> Forms Listbox just takes untyped Objects for its items and
> applies the same DisplayMember and ValueMember properties
> to all.
>
> -- TB
>
>