Link to home
Start Free TrialLog in
Avatar of syscomdev
syscomdev

asked on

Using a generic.dictionary as the source for a datagridview

vs2005 vb.net
Public Class test

Private displayValue As String
Private dbType As Integer
Property Display() As String
      Get
            Return displayValue
      End Get
      Set(ByVal value As String)
            displayValue = value
      End Set
End Property

Property DataType() As Integer
      Get
            Return dbType
      End Get
      Set(ByVal value As Integer)
            dbType = value
      End Set
End Property

Public Sub New(ByVal dspl As String, ByVal dt As Integer)
      Display = dspl
      DataType = dt
End Sub
End Class
I have a generic.dictionary [Dim tests As New Generic.Dictionary(Of String, test)] which i would like to bind to a datagridview

if it were a collection (which contained a series of class 'test'), I would :
      datagridview1.datasource = collName
      datagridview1.columns(0).datapropertyName = "Display"
      datagridview1.columns(1).datapropertyName = "DataType"

However I don't appear to be able to do the same thing with a dictionary. So far I found that you need to do:
      datagridview1.datasource = tests.values

But I do not know how to bind the specific value of the class for the dictionary.

Thank you
ASKER CERTIFIED SOLUTION
Avatar of graye
graye
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of syscomdev
syscomdev

ASKER

The one thing that I would lose would be the ability to find a value by a key, i.e.
tests("example1").datatype = 5.

The item method in the BindingList is only by numeric.
So is my basic choice which is more important? To be able to gather the data by key or to have it displayed?

I know I could have a simple data construct for the pairing, but was hoping to get around it.

Thank you for the example and any other assistance.