I
Ignacio Martínez
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
----------------------------------------------------------------------------
------
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
[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 said: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!
-----Original Message-----
ok, so basically I can't manually set the valuemember of a listbox item
(webcontrols are more flexible in this cases...)
thanx!!!!!!!!
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