PC Review


Reply
Thread Tools Rate Thread

Binding to Arraylist

 
 
Michael C#
Guest
Posts: n/a
 
      20th Mar 2005
I'm binding a Combobox to an Arraylist, and I'd like to set the ValueMember
and DisplayMember properties of the Combobox. Is this possible, or do I
need to bind to a DataTable?

Thanks


 
Reply With Quote
 
 
 
 
Ken Tucker [MVP]
Guest
Posts: n/a
 
      20th Mar 2005
Hi,

Yes you can bind to any property contained in a class stored in the
arraylist.

Ken
----------------------
"Michael C#" <(E-Mail Removed)> wrote in message
news:Xtk%d.1526$(E-Mail Removed)...
I'm binding a Combobox to an Arraylist, and I'd like to set the ValueMember
and DisplayMember properties of the Combobox. Is this possible, or do I
need to bind to a DataTable?

Thanks



 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      20th Mar 2005
"Michael C#" <(E-Mail Removed)> schrieb:
> I'm binding a Combobox to an Arraylist, and I'd like to set the
> ValueMember and DisplayMember properties of the Combobox. Is this
> possible


Yes.

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

 
Reply With Quote
 
Michael C#
Guest
Posts: n/a
 
      20th Mar 2005
Thank you

"Ken Tucker [MVP]" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Hi,
>
> Yes you can bind to any property contained in a class stored in the
> arraylist.
>
> Ken
> ----------------------
> "Michael C#" <(E-Mail Removed)> wrote in message
> news:Xtk%d.1526$(E-Mail Removed)...
> I'm binding a Combobox to an Arraylist, and I'd like to set the
> ValueMember
> and DisplayMember properties of the Combobox. Is this possible, or do I
> need to bind to a DataTable?
>
> Thanks
>
>
>



 
Reply With Quote
 
Michael C#
Guest
Posts: n/a
 
      20th Mar 2005

"Herfried K. Wagner [MVP]" <hirf-spam-me-(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "Michael C#" <(E-Mail Removed)> schrieb:
>> I'm binding a Combobox to an Arraylist, and I'd like to set the
>> ValueMember and DisplayMember properties of the Combobox. Is this
>> possible

>
> Yes.
>


Well as long as it's possible.


 
Reply With Quote
 
=?Utf-8?B?RGVubmlz?=
Guest
Posts: n/a
 
      20th Mar 2005
I believe that you have to set the DataSource name to "ArrayList" whereas for
a Datatable, you set this to the DataTable's name. At least this is what you
have to for binding the DataGrid to an ArrayList so I would suppose it's the
same for a combo box. The DataMember has no meaning when binding to an
arraylist.

"Michael C#" wrote:

>
> "Herfried K. Wagner [MVP]" <hirf-spam-me-(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > "Michael C#" <(E-Mail Removed)> schrieb:
> >> I'm binding a Combobox to an Arraylist, and I'd like to set the
> >> ValueMember and DisplayMember properties of the Combobox. Is this
> >> possible

> >
> > Yes.
> >

>
> Well as long as it's possible.
>
>
>

 
Reply With Quote
 
Michael C#
Guest
Posts: n/a
 
      20th Mar 2005
So you can't set the Value and a separate distince DisplayMember? For
instance:

1, Yes
2, No
3, Maybe

If I display and choose "No" in the Combobox, there is no way to retrieve
the value 2 which is related to that option? It seems like that's a bit of
important functionality to be missing.

"Dennis" <(E-Mail Removed)> wrote in message
news:BC588E8D-C297-4395-B1C1-(E-Mail Removed)...
>I believe that you have to set the DataSource name to "ArrayList" whereas
>for
> a Datatable, you set this to the DataTable's name. At least this is what
> you
> have to for binding the DataGrid to an ArrayList so I would suppose it's
> the
> same for a combo box. The DataMember has no meaning when binding to an
> arraylist.
>
> "Michael C#" wrote:
>
>>
>> "Herfried K. Wagner [MVP]" <hirf-spam-me-(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> > "Michael C#" <(E-Mail Removed)> schrieb:
>> >> I'm binding a Combobox to an Arraylist, and I'd like to set the
>> >> ValueMember and DisplayMember properties of the Combobox. Is this
>> >> possible
>> >
>> > Yes.
>> >

>>
>> Well as long as it's possible.
>>
>>
>>



 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      20th Mar 2005
"Michael C#" <(E-Mail Removed)> schrieb:
>>> I'm binding a Combobox to an Arraylist, and I'd like to set the
>>> ValueMember and DisplayMember properties of the Combobox. Is this
>>> possible

>>
>> Yes.
>>

>
> Well as long as it's possible.


???

Sample:

\\\
Private Sub Form1_Load( _
ByVal sender As Object, _
ByVal e As EventArgs _
) Handles MyBase.Load
Dim al As New ArrayList
For i As Integer = 1 To 20
Dim p As New Person
p.Name = "Name " & CStr(i)
p.Age = 70 - i
al.Add(p)
Next i
With Me.ListBox1
.DisplayMember = "Name"
.ValueMember = "Age"
.DataSource = al
End With
End Sub

Private Sub ListBox1_SelectedIndexChanged( _
ByVal sender As Object, _
ByVal e As EventArgs _
) Handles ListBox1.SelectedIndexChanged
MsgBox("Selected value: " & CStr(Me.ListBox1.SelectedValue))
End Sub
..
..
..
Public Class Person
Private m_Name As String
Private m_Age As Integer

Public Property Name() As String
Get
Return m_Name
End Get
Set(ByVal Value As String)
m_Name = Value
End Set
End Property

Public Property Age() As Integer
Get
Return m_Age
End Get
Set(ByVal Value As Integer)
m_Age = Value
End Set
End Property

Public Overrides Function ToString() As String
Return Me.Name & " (" & Me.Age.ToString() & ")"
End Function
End Class
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
 
Reply With Quote
 
Michael C#
Guest
Posts: n/a
 
      21st Mar 2005
Thank you for expounding on your initial 4-character response. I appreciate
it.

"Herfried K. Wagner [MVP]" <hirf-spam-me-(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "Michael C#" <(E-Mail Removed)> schrieb:
>>>> I'm binding a Combobox to an Arraylist, and I'd like to set the
>>>> ValueMember and DisplayMember properties of the Combobox. Is this
>>>> possible
>>>
>>> Yes.
>>>

>>
>> Well as long as it's possible.

>
> ???
>
> Sample:
>
> \\\
> Private Sub Form1_Load( _
> ByVal sender As Object, _
> ByVal e As EventArgs _
> ) Handles MyBase.Load
> Dim al As New ArrayList
> For i As Integer = 1 To 20
> Dim p As New Person
> p.Name = "Name " & CStr(i)
> p.Age = 70 - i
> al.Add(p)
> Next i
> With Me.ListBox1
> .DisplayMember = "Name"
> .ValueMember = "Age"
> .DataSource = al
> End With
> End Sub
>
> Private Sub ListBox1_SelectedIndexChanged( _
> ByVal sender As Object, _
> ByVal e As EventArgs _
> ) Handles ListBox1.SelectedIndexChanged
> MsgBox("Selected value: " & CStr(Me.ListBox1.SelectedValue))
> End Sub
> .
> .
> .
> Public Class Person
> Private m_Name As String
> Private m_Age As Integer
>
> Public Property Name() As String
> Get
> Return m_Name
> End Get
> Set(ByVal Value As String)
> m_Name = Value
> End Set
> End Property
>
> Public Property Age() As Integer
> Get
> Return m_Age
> End Get
> Set(ByVal Value As Integer)
> m_Age = Value
> End Set
> End Property
>
> Public Overrides Function ToString() As String
> Return Me.Name & " (" & Me.Age.ToString() & ")"
> End Function
> End Class
> ///
>
> --
> M S Herfried K. Wagner
> M V P <URL:http://dotnet.mvps.org/>
> V B <URL:http://classicvb.org/petition/>



 
Reply With Quote
 
J L
Guest
Posts: n/a
 
      21st Mar 2005
Why wont this work with a structure and combo box

Public Structure myStructure
Public Name As String
Public Title As String
End Structure

Dim arList As New ArrayList
Dim i As Integer

For i = 0 To 10
Dim ms As New myStructure
ms.Name = "Name " & i.ToString
ms.Title = "Title " & i.ToString
arList.Add(ms)
Next
'
With cmboMyTest
.DisplayMember = "Name"
.ValueMember = "Title"
.DataSource = arList
End With

When I run this, the combo box is filled with the fully qualified name
of the form and "+myStructure"

That is: "ObjectIntro.FormSecondTest+myStructure" is displayed in the
10 items of the combo box.

Thanks for all the help, always.

John

On Mon, 21 Mar 2005 00:45:28 +0100, "Herfried K. Wagner [MVP]"
<hirf-spam-me-(E-Mail Removed)> wrote:

>"Michael C#" <(E-Mail Removed)> schrieb:
>>>> I'm binding a Combobox to an Arraylist, and I'd like to set the
>>>> ValueMember and DisplayMember properties of the Combobox. Is this
>>>> possible
>>>
>>> Yes.
>>>

>>
>> Well as long as it's possible.

>
>???
>
>Sample:
>
>\\\
>Private Sub Form1_Load( _
> ByVal sender As Object, _
> ByVal e As EventArgs _
>) Handles MyBase.Load
> Dim al As New ArrayList
> For i As Integer = 1 To 20
> Dim p As New Person
> p.Name = "Name " & CStr(i)
> p.Age = 70 - i
> al.Add(p)
> Next i
> With Me.ListBox1
> .DisplayMember = "Name"
> .ValueMember = "Age"
> .DataSource = al
> End With
>End Sub
>
>Private Sub ListBox1_SelectedIndexChanged( _
> ByVal sender As Object, _
> ByVal e As EventArgs _
>) Handles ListBox1.SelectedIndexChanged
> MsgBox("Selected value: " & CStr(Me.ListBox1.SelectedValue))
>End Sub
>.
>.
>.
>Public Class Person
> Private m_Name As String
> Private m_Age As Integer
>
> Public Property Name() As String
> Get
> Return m_Name
> End Get
> Set(ByVal Value As String)
> m_Name = Value
> End Set
> End Property
>
> Public Property Age() As Integer
> Get
> Return m_Age
> End Get
> Set(ByVal Value As Integer)
> m_Age = Value
> End Set
> End Property
>
> Public Overrides Function ToString() As String
> Return Me.Name & " (" & Me.Age.ToString() & ")"
> End Function
>End Class
>///


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Binding an arraylist to a datalist npverni@gmail.com Microsoft ASP .NET 1 7th Mar 2006 12:50 AM
Arraylist binding Mr Newbie Microsoft VB .NET 3 6th Dec 2005 07:36 PM
Binding DataGrid To ArrayList Rami Microsoft VB .NET 5 6th Feb 2005 09:54 PM
ArrayList - DataGrid binding Jordan Microsoft C# .NET 1 13th Nov 2003 04:59 PM
Binding a datagrid to an arraylist Piyush Microsoft Dot NET Framework Forms 0 20th Oct 2003 09:24 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:51 AM.