Groups | Blog | Home
all groups > vb.net controls > july 2005 >

vb.net controls : Data Bound Custom Control


Rlrcstr
7/11/2005 4:05:48 PM
Can someone point me to an example of creating data bound custom controls?
I want to create my own customized listbox that I can bind to a custom
collection of objects. Thanks.

Jerry


Ken Tucker [MVP]
7/11/2005 7:35:26 PM
Hi,

You can already do that.

Dim arBook As ArrayList



Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim cBook As Book

Dim x As Integer

arBook = New ArrayList

For x = 1 To 10

cBook = New Book

cBook.Name = "Book " & x.ToString

cBook.ID = x

arBook.Add(cBook)

Next

ListBox1.DataSource = arBook

ListBox1.DisplayMember = "Name"

End Sub


The class


Public Class Book

Private m_name As String

Dim m_ID As String

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 ID() As String

Get

Return m_ID

End Get

Set(ByVal Value As String)

m_ID = Value

End Set

End Property

End Class


Ken
----------------
[quoted text, click to view]
Can someone point me to an example of creating data bound custom controls?
I want to create my own customized listbox that I can bind to a custom
collection of objects. Thanks.

Jerry



Rlrcstr
7/11/2005 7:51:48 PM
Yes. I know I can do that... I want to create my own control for
displaying the data. It is a listbox type of control, but it isn't based on
a ListBox. There were many issues drawing the inner controls, etc. when I
tried inheriting from a ListBox. Using a scrollable panel, I was able to
overcome the display issues, but I need to know how I can add my own data
bindings. Do you have to just iterate through the full list and assign
bindings to all the controls, or is there some mechanism that I can
implement using the binding classes?

I'm not sure if I'm explaining this well enough, so feel free to ask for
clarification where needed.

Thanks.

Jerry




[quoted text, click to view]

Ken Tucker [MVP]
7/12/2005 5:31:38 AM
Hi,

Maybe this will help.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwinforms/html/custcntrlsamp3.asp

Ken
--------------------
[quoted text, click to view]
Yes. I know I can do that... I want to create my own control for
displaying the data. It is a listbox type of control, but it isn't based on
a ListBox. There were many issues drawing the inner controls, etc. when I
tried inheriting from a ListBox. Using a scrollable panel, I was able to
overcome the display issues, but I need to know how I can add my own data
bindings. Do you have to just iterate through the full list and assign
bindings to all the controls, or is there some mechanism that I can
implement using the binding classes?

I'm not sure if I'm explaining this well enough, so feel free to ask for
clarification where needed.

Thanks.

Jerry




[quoted text, click to view]


Jerry Camel
7/12/2005 9:54:31 AM
That's perfect. Exactly what I needed. Why is it that I can't find this
stuff when I search? Thanks, again.

Jerry


[quoted text, click to view]

AddThis Social Bookmark Button