473,387 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Bind a listbox to a dictionary object

I have a dictionary oject I created and I want to bind a listbox to it. I
am including the code for the dictionary object.

Here is the error I am getting:

"System.Exception: Complex DataBinding accepts as a data source either an
IList or an IListSource

at System.Windows.Forms.ListControl.set_DataSource(Ob ject value)

at USBSecure.frmUSBSecure.ExchangeInputAndOutputRepor ts() in
d:\usbsecure\USBSecure\frmUSBSecure.vb:line 743"
I tried to implement the IList interface and got the following:
'USBSecure.FOBS' must implement 'Overridable Function IndexOf(value As
Object) As Integer' for interface 'System.Collections.IList'.

So I try to override it and get an error that I can't do this because it is
not overriding a sub in the base class. All I want is to bind my listbox to
my dictionary. Any help is appreciated.

John
FOB Dictionary CODE:
Imports System.Collections

Public Class FOB

Public Enum FOBStatus

Enabled = 1

Disabled = 2

Validated = 3

Invalid = 4

End Enum

Private strFOBID As String

Private intFOBStatus As Integer

#Region "Constructors"

Public Sub New(ByVal strFOBNumber As String, ByVal intFOBStat As Integer)

strFOBID = strFOBNumber

intFOBStatus = intFOBStat

End Sub

Public Sub New()

End Sub

#End Region

#Region "Properties"

Public Property FOBID() As String

Get

Return strFOBID

End Get

Set(ByVal Value As String)

strFOBID = Value

End Set

End Property

Public Property Status() As Integer

Get

Return intFOBStatus

End Get

Set(ByVal Value As Integer)

intFOBStatus = Value

End Set

End Property

#End Region

End Class

Public Class FOBS

Inherits DictionaryBase

#Region "Public Methods"

Public Sub add(ByVal KeyFOB As FOB)

MyBase.Dictionary.Add(KeyFOB.FOBID, KeyFOB)

End Sub

Public Sub add(ByVal KeyFOB As String, ByVal FOBStatus As Integer)

MyBase.Dictionary.Add(KeyFOB, New FOB(KeyFOB, FOBStatus))

End Sub

Public Sub Remove(ByVal FOBID As String)

MyBase.Dictionary.Remove(FOBID)

End Sub

Public Sub Remove(ByVal KeyFOB As FOB)

MyBase.Dictionary.Remove(KeyFOB.FOBID)

End Sub

Public Function Contains(ByVal Keyfob As FOB) As Boolean

Return MyBase.Dictionary.Contains(Keyfob.FOBID)

End Function

Public Function Contains(ByVal KeyFOB As String) As Boolean

Return MyBase.Dictionary.Contains(KeyFOB)

End Function

#End Region

#Region "Properties"

Default Public Property FOB(ByVal KeyFOB As String) As FOB

Get

Return MyBase.Dictionary.Item(KeyFOB)

End Get

Set(ByVal Value As FOB)

MyBase.Dictionary.Item(KeyFOB) = Value

End Set

End Property

#End Region

Protected Overrides Sub finalize()

MyBase.Finalize()

End Sub

End Class


Nov 21 '05 #1
1 9221
Hi,

Here is a custom dictonary I use for binding to. I added a
bindablelist property which returns an arraylist of the values. You can
bind to the bindablelist.

Public Class BindableDictonary
Inherits DictionaryBase
Default Public Property Item(ByVal key As Object) As Object
Get
Return Dictionary(key)
End Get
Set(ByVal Value As Object)
Dictionary(key) = Value
End Set
End Property

Public ReadOnly Property Keys() As ICollection
Get
Return Dictionary.Keys
End Get
End Property

Public ReadOnly Property Values() As ICollection
Get
Return Dictionary.Values
End Get
End Property

Public Sub Add(ByVal key As Object, ByVal value As Object)
Dictionary.Add(key, value)
End Sub 'Add

Public Function Contains(ByVal key As Object) As Boolean
Return Dictionary.Contains(key)
End Function 'Contains

Public Sub Remove(ByVal key As Object)
Dictionary.Remove(key)
End Sub 'Remove
Public ReadOnly Property BindableList() As ArrayList
Get
Dim al As New ArrayList
For Each de As DictionaryEntry In Me.Dictionary
al.Add(de.Value)
Next
Return al
End Get
End Property
End Class
Simple example

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

For x As Int16 = 10 To 0 Step -1
Dim cls As New Bindto
With cls
.ColA = String.Format("Col A {0}", x)
.ColB = String.Format("B {0}", x)
End With
bd.Add(x, cls)
Next

DataGrid1.DataSource = bd.BindableList
End Sub
End Class
Public Class Bindto
Dim mstrColA As String
Dim mstrColB As String

Public Property ColA() As String
Get
Return mstrColA
End Get
Set(ByVal Value As String)
mstrColA = Value
End Set
End Property

Public Property ColB() As String
Get
Return mstrColB
End Get
Set(ByVal Value As String)
mstrColB = Value
End Set
End Property
End Class

Ken
-------------------
"john wright" <ri**********@hotmail.com> wrote in message
news:On**************@TK2MSFTNGP12.phx.gbl...
I have a dictionary oject I created and I want to bind a listbox to it. I
am including the code for the dictionary object.

Here is the error I am getting:

"System.Exception: Complex DataBinding accepts as a data source either an
IList or an IListSource

at System.Windows.Forms.ListControl.set_DataSource(Ob ject value)

at USBSecure.frmUSBSecure.ExchangeInputAndOutputRepor ts() in
d:\usbsecure\USBSecure\frmUSBSecure.vb:line 743"
I tried to implement the IList interface and got the following:
'USBSecure.FOBS' must implement 'Overridable Function IndexOf(value As
Object) As Integer' for interface 'System.Collections.IList'.

So I try to override it and get an error that I can't do this because it
is not overriding a sub in the base class. All I want is to bind my
listbox to my dictionary. Any help is appreciated.

John
FOB Dictionary CODE:
Imports System.Collections

Public Class FOB

Public Enum FOBStatus

Enabled = 1

Disabled = 2

Validated = 3

Invalid = 4

End Enum

Private strFOBID As String

Private intFOBStatus As Integer

#Region "Constructors"

Public Sub New(ByVal strFOBNumber As String, ByVal intFOBStat As Integer)

strFOBID = strFOBNumber

intFOBStatus = intFOBStat

End Sub

Public Sub New()

End Sub

#End Region

#Region "Properties"

Public Property FOBID() As String

Get

Return strFOBID

End Get

Set(ByVal Value As String)

strFOBID = Value

End Set

End Property

Public Property Status() As Integer

Get

Return intFOBStatus

End Get

Set(ByVal Value As Integer)

intFOBStatus = Value

End Set

End Property

#End Region

End Class

Public Class FOBS

Inherits DictionaryBase

#Region "Public Methods"

Public Sub add(ByVal KeyFOB As FOB)

MyBase.Dictionary.Add(KeyFOB.FOBID, KeyFOB)

End Sub

Public Sub add(ByVal KeyFOB As String, ByVal FOBStatus As Integer)

MyBase.Dictionary.Add(KeyFOB, New FOB(KeyFOB, FOBStatus))

End Sub

Public Sub Remove(ByVal FOBID As String)

MyBase.Dictionary.Remove(FOBID)

End Sub

Public Sub Remove(ByVal KeyFOB As FOB)

MyBase.Dictionary.Remove(KeyFOB.FOBID)

End Sub

Public Function Contains(ByVal Keyfob As FOB) As Boolean

Return MyBase.Dictionary.Contains(Keyfob.FOBID)

End Function

Public Function Contains(ByVal KeyFOB As String) As Boolean

Return MyBase.Dictionary.Contains(KeyFOB)

End Function

#End Region

#Region "Properties"

Default Public Property FOB(ByVal KeyFOB As String) As FOB

Get

Return MyBase.Dictionary.Item(KeyFOB)

End Get

Set(ByVal Value As FOB)

MyBase.Dictionary.Item(KeyFOB) = Value

End Set

End Property

#End Region

Protected Overrides Sub finalize()

MyBase.Finalize()

End Sub

End Class

Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: VbScripter | last post by:
In the code below, I have an editItemTemplate that will have to have a long list of ip's bound to it. The problem is that the lisbox is not seen by asp.net until after the datalist containing it...
1
by: Microskills | last post by:
I am a new VB.NET programmer. I am writing a dictionary program with a Dictionary file has over 60000 entries. When user starts typing a word in the searchbox, I want to show words that start with...
1
by: Microskills | last post by:
I am a new VB.NET programmer. I am writing a dictionary program with a Dictionary file has over 60000 entries. When user starts typing a word in the searchbox, I want to show words that start with...
6
by: Fao, Sean | last post by:
Is it possible to bind a GridView to a generic Dictionary object? When I try it in my ASP.NET application, it throws an exception acknowledging that the specified field or property does not exist....
2
by: Juliano.net | last post by:
Can I bind an object of a class to a ListBox?
2
by: John Grandy | last post by:
Is it possible to bind a Dictionary to a DropDownList ? The most obvious code fails : Dictionary<string,stringdictionary = new Dictionary<string,string> dictionary.Add("Name1","Value1");...
2
by: =?Utf-8?B?TWFobW91ZCBTaGFiYW4=?= | last post by:
i have a problem in adding new listbox items i don't need to allow adding multible items with the same textvalue ex: if current items are: green red
1
by: MariaKhan | last post by:
?? bind DataSet with listbox ??? ?? bind DataSet with listbox ??? ?? bind DataSet with listbox ??? ?? bind DataSet with listbox ??? ?? bind DataSet with listbox ???
5
by: jrobbins | last post by:
public IEnumerable<AuthorizationObjectClass> GetEmployeeNoAuthorizations(SqlInt32 PersonnelNumber) { DataSet ds; AuthorizationObjectClass auth = new...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.