Bind strongly typed dictionary class to datagrid?

D

Dot net work

Say I create my own strongly typed dictionary class.

How do you bind, for instance, the key column of this class to a
datagrid?

I've tried a few different ways, but each time I get this error:

A field or property with the name 'keycol' was not found on the
selected datasource.

I understand that it's got something to do with using the Property
keyword, rather than having a public field, but I'm still having
difficulty.

TIA,
-dnw.
 
D

Dot net work

Hello.

I still can't bind a strongly typed dictionary object to a datagrid.
Please can some datagrid expert offer a clue...

My simple calling code is:

Dim oDic As New clsMyDictionary() 'Make a dictionary object
Dim oStruc As New clsMyDictionary.stcMyStructure() 'Make a structure
object that goes inside the dictionary object

oStruc.COL1 = 100
oStruc.COL2 = "a string"
oDic.Add(1, oStruc)

DataGrid1.DataSource = oDic
DataGrid1.DataBind()

(The binding fails with an error of: A field or property with the
name 'COL1' was not found on the selected datasource.)


My class code is:

Public Class clsMyDictionary
Inherits System.Collections.DictionaryBase

Public Structure stcMyStructure
Private _COL1 As Integer
Private _COL2 As String

Public Property COL1() As Integer
Get
Return _COL1
End Get
Set(ByVal Value As Integer)
_COL1 = Value
End Set
End Property
Public Property COL2() As String
Get
Return _COL2
End Get
Set(ByVal Value As String)
_COL2 = Value
End Set
End Property
End Structure

Public Shadows Sub Add(ByVal iKey As Integer, ByVal oStruc As
stcMyStructure)
dictionary.Add(iKey, oStruc)
End Sub

'I thought this might help with the binding, but alas...
Public Overloads ReadOnly Property Item(ByVal iIndex As Integer)
As stcMyStructure
Get
Return DirectCast(dictionary.Item(iIndex), stcMyStructure)
End Get
End Property
End Class


Any tips much appreciated.
-dnw.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top