473,728 Members | 1,454 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Excepti on: Complex DataBinding accepts as a data source either an
IList or an IListSource

at System.Windows. Forms.ListContr ol.set_DataSour ce(Object value)

at USBSecure.frmUS BSecure.Exchang eInputAndOutput Reports() in
d:\usbsecure\US BSecure\frmUSBS ecure.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.Collect ions.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.Collecti ons

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 "Constructo rs"

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.Dictiona ry.Add(KeyFOB.F OBID, KeyFOB)

End Sub

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

MyBase.Dictiona ry.Add(KeyFOB, New FOB(KeyFOB, FOBStatus))

End Sub

Public Sub Remove(ByVal FOBID As String)

MyBase.Dictiona ry.Remove(FOBID )

End Sub

Public Sub Remove(ByVal KeyFOB As FOB)

MyBase.Dictiona ry.Remove(KeyFO B.FOBID)

End Sub

Public Function Contains(ByVal Keyfob As FOB) As Boolean

Return MyBase.Dictiona ry.Contains(Key fob.FOBID)

End Function

Public Function Contains(ByVal KeyFOB As String) As Boolean

Return MyBase.Dictiona ry.Contains(Key FOB)

End Function

#End Region

#Region "Properties "

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

Get

Return MyBase.Dictiona ry.Item(KeyFOB)

End Get

Set(ByVal Value As FOB)

MyBase.Dictiona ry.Item(KeyFOB) = Value

End Set

End Property

#End Region

Protected Overrides Sub finalize()

MyBase.Finalize ()

End Sub

End Class


Nov 21 '05 #1
1 9256
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 BindableDictona ry
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.Valu es
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.Cont ains(key)
End Function 'Contains

Public Sub Remove(ByVal key As Object)
Dictionary.Remo ve(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(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim bd As New BindableDictona ry

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.DataS ource = 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**********@h otmail.com> wrote in message
news:On******** ******@TK2MSFTN GP12.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.Excepti on: Complex DataBinding accepts as a data source either an
IList or an IListSource

at System.Windows. Forms.ListContr ol.set_DataSour ce(Object value)

at USBSecure.frmUS BSecure.Exchang eInputAndOutput Reports() in
d:\usbsecure\US BSecure\frmUSBS ecure.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.Collect ions.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.Collecti ons

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 "Constructo rs"

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.Dictiona ry.Add(KeyFOB.F OBID, KeyFOB)

End Sub

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

MyBase.Dictiona ry.Add(KeyFOB, New FOB(KeyFOB, FOBStatus))

End Sub

Public Sub Remove(ByVal FOBID As String)

MyBase.Dictiona ry.Remove(FOBID )

End Sub

Public Sub Remove(ByVal KeyFOB As FOB)

MyBase.Dictiona ry.Remove(KeyFO B.FOBID)

End Sub

Public Function Contains(ByVal Keyfob As FOB) As Boolean

Return MyBase.Dictiona ry.Contains(Key fob.FOBID)

End Function

Public Function Contains(ByVal KeyFOB As String) As Boolean

Return MyBase.Dictiona ry.Contains(Key FOB)

End Function

#End Region

#Region "Properties "

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

Get

Return MyBase.Dictiona ry.Item(KeyFOB)

End Get

Set(ByVal Value As FOB)

MyBase.Dictiona ry.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
1923
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 is exposed. Is there a way to bind the ddl inside of an already databound templated column? Thanks , of course Michael
1
2252
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 the text in the search box. For example if user enters GA lstbox will show GAB GABARDINE GABLE ...
1
2278
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 the text in the search box. For example if user enters GA lstbox will show GAB GABARDINE GABLE ... ...
6
29203
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. The problem, I think, is that the GridView cannot see "inside" of the generic Dictionary. I suspect this because setting the AutoGenerateColumns property of the GridView causes the GridView to display only the Key property, which is, of...
2
1318
by: Juliano.net | last post by:
Can I bind an object of a class to a ListBox?
2
24557
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"); //add some more items ... DropDownList.DataSource = dictionary;
2
2970
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
1532
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
4755
by: jrobbins | last post by:
public IEnumerable<AuthorizationObjectClass> GetEmployeeNoAuthorizations(SqlInt32 PersonnelNumber) { DataSet ds; AuthorizationObjectClass auth = new AuthorizationObjectClass(); try { //EmployeeObjectClass Emp = new EmployeeObjectClass(); Emp.PersonnelNumber = PersonnelNumber; ds = data.GetNotSelectedAuthorizations(Emp); ...
0
8896
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8755
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9416
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9269
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6012
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4523
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4787
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2647
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.